fix(reporter): strip ansi from test stdout when colors are disabled#40688
Conversation
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
Test results for "MCP"6 failed 7009 passed, 1058 skipped Merge workflow run. |
Test results for "tests 1"2 flaky41658 passed, 851 skipped Merge workflow run. |
|
Thank you ! |
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>
Summary
stdout/stderrwith aWritablethat strips ANSI escapes whenuseColorsis false (e.g.FORCE_COLOR=0), so user-printed ANSI sequences and reporter cursor codes don't leak into non-color output.Fixes #40683