Fix node test reporter not stripping some diffs because of coloring
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
🦋 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
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.
@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
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.