Skip to content

fix(reporter): strip ansi from test stdout when colors are disabled#40688

Merged
pavelfeldman merged 1 commit into
microsoft:mainfrom
pavelfeldman:fix-40683
May 7, 2026
Merged

fix(reporter): strip ansi from test stdout when colors are disabled#40688
pavelfeldman merged 1 commit into
microsoft:mainfrom
pavelfeldman:fix-40683

Conversation

@pavelfeldman
Copy link
Copy Markdown
Member

Summary

  • Wraps the reporter's stdout/stderr with a Writable that strips ANSI escapes when useColors is false (e.g. FORCE_COLOR=0), so user-printed ANSI sequences and reporter cursor codes don't leak into non-color output.

Fixes #40683

When useColors is false (e.g. FORCE_COLOR=0), wrap the reporter's
stdout/stderr with a Writable that strips ANSI escapes before
forwarding. This ensures user-printed ANSI sequences and reporter
cursor codes do not appear in non-color outputs.

Fixes microsoft#40683
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Test results for "MCP"

6 failed
❌ [chrome] › mcp/test-run.spec.ts:126 › test_run should stop when aborted @mcp-windows-latest-chrome
❌ [firefox] › mcp/cli-session.spec.ts:99 › session stops when browser exits @mcp-windows-latest-firefox
❌ [msedge] › mcp/annotate.spec.ts:57 › should capture multiple screenshots in one annotation @mcp-windows-latest-msedge
❌ [msedge] › mcp/annotate.spec.ts:110 › should abort annotation when last screenshot is removed @mcp-windows-latest-msedge
❌ [webkit] › mcp/config.ini.spec.ts:57 › ini config sets browser launch options @mcp-windows-latest-webkit
❌ [webkit] › mcp/config.spec.ts:138 › browser_get_config returns merged config from file, env and cli @mcp-windows-latest-webkit

7009 passed, 1058 skipped


Merge workflow run.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Test results for "tests 1"

2 flaky ⚠️ [chromium-library] › library/video.spec.ts:476 › screencast › should capture static page in persistent context @smoke `@chromium-ubuntu-22.04-node22`
⚠️ [playwright-test] › ui-mode-test-output.spec.ts:118 › should collapse repeated console messages for test `@ubuntu-latest-node22`

41658 passed, 851 skipped


Merge workflow run.

@pavelfeldman pavelfeldman merged commit 1938c9f into microsoft:main May 7, 2026
41 of 45 checks passed
@williamdes
Copy link
Copy Markdown

Thank you !
I was doing the same sort of contribution today
After more research I ended up making #40903 anyway

williamdes added a commit to williamdes/playwright that referenced this pull request May 20, 2026
Per https://no-color.org/, any non-empty NO_COLOR should disable
ANSI output. Today the bundled chalk honors it for colors, but
the list reporter's cursor-up (\x1b[NA) / clear-line (\x1b[2K)
codes are emitted from the TTY path and aren't gated on NO_COLOR
at all — so users setting NO_COLOR=1 still see cursor codes in
piped / tee'd output.

When PLAYWRIGHT_FORCE_TTY is unset (explicit override still
wins), treat non-empty NO_COLOR as implying isTTY=false so the
reporters skip the TTY repaint path entirely. Also gate useColors
on NO_COLOR for consistency, matching chalk's internal check.

FORCE_COLOR=0 behavior is unchanged: it still disables colors as
before, and the existing StripAnsiStream from microsoft#40688 already
sanitizes its piped output. Reviewer asked to scope this PR to
NO_COLOR only.

Test in reporter-list.spec.ts asserts NO_COLOR=1 produces no
cursor-repaint codes. Docs in test-reporters-js.md add a NO_COLOR
row to all three reporter tables and note the PFT-default
fallback.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Workers force FORCE_COLOR=1 into spawned child env, ignoring parent NO_COLOR / FORCE_COLOR=0

3 participants