hardhat icon indicating copy to clipboard operation
hardhat copied to clipboard

Fix node test reporter not stripping some diffs because of coloring

Open antico5 opened this issue 9 months ago • 2 comments

The code inside error-formating#formatSingleError is removing the diff text generated by the node:test error, so we can append the one generated by us (using jest-diff).

It was failing to find some of the diffs when color was enabled on the terminal (e.g. on my system, the tests for the reporter don't pass on v-next branch).

This PR disables color via env. variable , and restores it just after running the tests. This env. var doesn't affect our own diff coloring (for which we use jest-diff).

Also I set the env. var on the integration tests suite, so tests now pass on my system besides just the CI

Closes #6688

image

image

antico5 avatar May 24 '25 06:05 antico5

🦋 Changeset detected

Latest commit: 72de64e54b65206b7c74520d8eea3587e13adc3e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 20 packages
Name Type
@nomicfoundation/hardhat-node-test-reporter Patch
@nomicfoundation/hardhat-node-test-runner Patch
hardhat Patch
@nomicfoundation/hardhat-errors Patch
@nomicfoundation/hardhat-ethers-chai-matchers Patch
@nomicfoundation/hardhat-ignition Patch
@nomicfoundation/ignition-core Patch
@nomicfoundation/hardhat-ignition-ethers Patch
@nomicfoundation/ignition-ui Patch
@nomicfoundation/hardhat-ignition-viem Patch
@nomicfoundation/hardhat-keystore Patch
@nomicfoundation/hardhat-mocha Patch
@nomicfoundation/hardhat-network-helpers Patch
@nomicfoundation/hardhat-test-utils Patch
@nomicfoundation/hardhat-typechain Patch
@nomicfoundation/hardhat-utils Patch
@nomicfoundation/hardhat-toolbox-mocha-ethers Patch
@nomicfoundation/hardhat-viem Patch
@nomicfoundation/hardhat-viem-matchers Patch
@nomicfoundation/hardhat-zod-utils Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar May 24 '25 06:05 changeset-bot[bot]

Oh, i never realized that this was because of the colors!

I wonder if we can make something similar, but in the reporter, no the test run. So that the reporter logic is self-contained.

alcuadrado avatar May 28 '25 13:05 alcuadrado

@antico5 I did a little exploration on forcing the colors for the tests and trying to disable them from within the reporter - https://github.com/NomicFoundation/hardhat/pull/6769

galargh avatar May 29 '25 13:05 galargh

Nice! Let's just add process.env.FORCE_COLOR = 1 before https://github.com/NomicFoundation/hardhat/blob/v-next/v-next/hardhat-node-test-reporter/integration-tests/index.ts#L85. That way we'll see whether the colors are correctlys tripped in CI.

galargh avatar May 29 '25 14:05 galargh