Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set chalk.level manually to prevent FORCE_COLOR leaks #14396

Closed
wants to merge 11 commits into from

Conversation

aweebit
Copy link

@aweebit aweebit commented Aug 9, 2023

Summary

Fixes #14391.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Aug 9, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

@netlify
Copy link

netlify bot commented Aug 9, 2023

Deploy Preview for jestjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 356d99c
🔍 Latest deploy log https://app.netlify.com/sites/jestjs/deploys/64d5962b14d22f00082ec547
😎 Deploy Preview https://deploy-preview-14396--jestjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@aweebit
Copy link
Author

aweebit commented Aug 10, 2023

The changes are breaking as the checks on e299a06 clearly demonstrate: tests are broken when testing Jest itself and expecting colored output.

Update: Now, the color support is deduced from the environment where Jest is running (unless FORCE_COLOR is set explicitly in a setup file), just like when using runInBand. Still breaking.

package.json Outdated
@@ -93,7 +93,7 @@
"clean-e2e": "node ./scripts/cleanE2e.mjs",
"crowdin:upload": "echo 'Uploading sources to Crowdin' && crowdin upload sources --config ./crowdin.yaml",
"crowdin:download": "echo 'Downloading translations from Crowdin' && crowdin download --config ./crowdin.yaml",
"jest": "node ./packages/jest-cli/bin/jest.js",
"jest": "FORCE_COLOR=1 node ./packages/jest-cli/bin/jest.js",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On CI the test-ci-partial:parallel script is used:

run: yarn test-ci-partial:parallel --max-workers ${{ steps.cpu-cores.outputs.count }} --shard=${{ matrix.shard }}

It includes the --color flag, so all should work without FORCE_COLOR=1 adding:

"test-ci-partial:parallel": "yarn jest --color --config jest.config.ci.mjs",

Copy link
Author

@aweebit aweebit Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrazauskas This is what you said in #14391 (comment):

The trick is that --colors is not passed anywhere and does not exist in Jest’s logic at all. chalk simply checks if --colors (or any numerous variation of it) is present in process.argv.

I actually think it should stay this way. In my opinion, having --color and the like have the same effect as setting FORCE_COLOR, or introducing any other means to set the color level for both the framework and the tests at the same time would be a bad decision because the uses of colors in the two have completely different meanings.

One might want to test colored output of a program that can produce such output in an environment that does not support colored output at all, and that would be perfectly valid. One might also want to ignore output coloring in tests and only focus on the contents of the output in an environment that supports colored output, but then using --no-color for this would be strange because that would also disable colors in the framework output, which we don't want.

Actually, my original solution with the FORCE_COLOR=1 prefix is also bad with respect to what I have just explained since it leaves no option to disable colors in the framework output.

Another problem I noticed is that if tests were to be run in an environment with no color support, then (almost?) all snapshot tests would fail because snapshots for the repo are apparently produced in an environment where there is such support, and the current behavior is essentially to simply let tests deduce the color level from the environment.

I solved both problems by adding a setup file to jest.config.mjs in which FORCE_COLOR is set to '1' for all tests, see b3558b7. (The configuration is only for internal Jest testing, so #14391 would still be fixed by merging this PR.)

@aweebit
Copy link
Author

aweebit commented Aug 11, 2023

Not quite sure what exactly I did in 356d99c in order to fix the broken tests and why it only became necessary after 28d16ae. Extra attention from reviewers is required.

Copy link

github-actions bot commented Nov 9, 2023

This PR is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Nov 9, 2023
@aweebit
Copy link
Author

aweebit commented Nov 9, 2023

The original issue is still not resolved. I might come back to this PR later to add tests and have a look at what else I can improve.

@github-actions github-actions bot removed the Stale label Nov 9, 2023
Copy link

github-actions bot commented Feb 7, 2024

This PR is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Feb 7, 2024
Copy link

github-actions bot commented Mar 8, 2024

This PR was closed because it has been stalled for 30 days with no activity. Please open a new PR if the issue is still relevant, linking to this one.

1 similar comment
Copy link

github-actions bot commented Mar 8, 2024

This PR was closed because it has been stalled for 30 days with no activity. Please open a new PR if the issue is still relevant, linking to this one.

@github-actions github-actions bot closed this Mar 8, 2024
@github-actions github-actions bot closed this Mar 8, 2024
Copy link

github-actions bot commented Apr 9, 2024

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: FORCE_COLOR set internally leaks through to tests on Windows after upgrade to Node.js v18.17.0
2 participants