Skip to content

test(fmt,internal,cli/unstable): fix test failures with NO_COLOR - #7334

Open
miso-devel wants to merge 4 commits into
denoland:mainfrom
miso-devel:fix/7322-no-color-tests
Open

miso-devel wants to merge 4 commits into
denoland:mainfrom
miso-devel:fix/7322-no-color-tests

Conversation

@miso-devel

Copy link
Copy Markdown
Contributor

Fixes #7322.

When NO_COLOR is set, the implementation correctly disables colored output. However, several tests in fmt, internal, and cli always expect ANSI escape codes, so they fail depending on the caller's environment.

This PR makes those tests explicitly enable colors instead of relying on the environment. It uses stubProperty to set Deno.noColor to false. For modules that capture the setting at initialization, the tests use dynamic imports so the stub is applied before the modules are loaded. For code that reads the setting at runtime, the stub is applied within the relevant tests.

Testing

Ran each test file individually with NO_COLOR=1 before and after the changes:

NO_COLOR=1 deno test --no-lock fmt/colors_test.ts
NO_COLOR=1 deno test --no-lock --allow-run internal/styles_test.ts
NO_COLOR=1 deno test --no-lock cli/unstable_spinner_test.ts
NO_COLOR=1 deno test --no-lock fmt/printf_test.ts
Test file Before After
fmt/colors_test.ts 1 passed, 53 failed 54 passed, 0 failed
internal/styles_test.ts 2 passed, 10 failed 12 passed, 0 failed
cli/unstable_spinner_test.ts 3 passed, 8 failed (9 failed steps) 11 passed (9 steps), 0 failed
fmt/printf_test.ts 32 passed, 1 failed 33 passed, 0 failed

The existing noColor subprocess test passed both before and after the changes.

@codecov

codecov Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.04%. Comparing base (f834d02) to head (7dc3b2c).

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #7334    +/-   ##
========================================
  Coverage   95.04%   95.04%            
========================================
  Files         619      618     -1     
  Lines       52012    51757   -255     
  Branches     9450     9401    -49     
========================================
- Hits        49434    49192   -242     
+ Misses       2031     2022     -9     
+ Partials      547      543     -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(fmt): color tests fail when NO_COLOR is set

1 participant