test: make drift output test independent of colour detection - #7057
Draft
rrama wants to merge 1 commit into
Draft
Conversation
The "Test describe output" case compares getHumanReadableAnalysis against the all.console fixture, which contains hard-coded ANSI escapes. Whether those escapes are produced is decided by chalk from the ambient environment, so the test only passes when chalk believes colour is supported. chalk 2.4.2 ships supports-color 5.5.0, which returns level 0 for a non-TTY stream before it considers CI vendor variables. CircleCI runs steps under a pty so the test passes there, but piping jest output anywhere else -- a local run, an editor test runner, a container -- produces plain text and a large confusing diff. Pin chalk's colour level for this block and restore it afterwards, so the assertion tests the formatting rather than the terminal it happens to run in. Verified passing with no FORCE_COLOR, FORCE_COLOR=1 and FORCE_COLOR=0. Co-authored-by: Cursor <cursoragent@cursor.com>
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Submission Checklist
What does this PR do?
Makes
test/jest/unit/lib/iac/drift/drift.spec.ts→Test describe output › test output for known analysispass regardless of the terminal it runs in.That test compares
getHumanReadableAnalysisoutput against thefixtures/all.consolegolden file, which contains hard-coded ANSI escapes (\e[1m…\e[22m,\e[34m…\e[39m). Whether those escapes are emitted at all is decided by chalk from the ambient environment, so today the test passes only when chalk happens to think colour is supported.Concretely: chalk 2.4.2 depends on supports-color 5.5.0, which returns level
0for a non-TTY stream before it gets as far as checking CI vendor variables. CircleCI runs steps under a pty, so the test passes in CI. Anywhere jest output is piped — a plain local run, an editor-integrated runner, a container, a sandboxed agent — chalk emits plain text and the test fails with a large and fairly baffling whitespace-looking diff:This wasn't hypothetical: it's reproducible on a normal dev machine with full network access and valid credentials, and it was originally reported as an environment problem because the failure looks nothing like a colour issue.
The fix pins chalk's colour level for that
describeblock and restores the previous value afterwards, so the assertion covers the formatting logic rather than the terminal it happens to run in.Where should the reviewer start?
The whole diff is ~16 lines in
drift.spec.ts. Worth confirming you agree with the direction: this keeps the golden file asserting on colours (rather than stripping ANSI from both sides, which would silently stop testing them).How should this be manually tested?
On
mainthe first and third fail. Fullnpm run test:unitwas also run: this suite passes and nothing else changed behaviour.What's the product update that needs to be communicated to CLI users?
None — test-only change, no shipped code touched.
Risk assessment: Low
Test-only. The chalk level is scoped to one
describeblock and restored inafterAll, and jest gives each test file its own module registry, so no other suite is affected.Made with Cursor