Skip to content

fix(reporter): honor NO_COLOR in list/line/dot reporters#40903

Open
williamdes wants to merge 1 commit into
microsoft:mainfrom
williamdes:fix/reporter-force-color-implies-non-tty
Open

fix(reporter): honor NO_COLOR in list/line/dot reporters#40903
williamdes wants to merge 1 commit into
microsoft:mainfrom
williamdes:fix/reporter-force-color-implies-non-tty

Conversation

@williamdes
Copy link
Copy Markdown

@williamdes williamdes commented May 19, 2026

Context

Per the NO_COLOR convention, any non-empty NO_COLOR value should disable ANSI color output. Playwright's bundled chalk honors that internally, but code in packages/playwright/src/reporters/base.ts that consults useColors doesn't — so e.g. the StripAnsiStream wrapper introduced in #40688 only kicks in when FORCE_COLOR=0 is also set.

What

NO_COLOR added to the existing useColors disabling branch in terminalScreen. Any non-empty NO_COLOR now disables colors, matching chalk's behavior and the no-color.org spec.

isTTY is left unchanged — no-color.org makes no claims about terminal shape, only about colors. (An earlier revision of this PR also gated isTTY on NO_COLOR; reverted per review feedback.)

Tests

One case added in reporter-list.spec.ts mirroring the existing FORCE_COLOR=0 test: asserts NO_COLOR=1 strips ANSI from test stdout / stderr.

Docs

docs/src/test-reporters-js.md — list/line/dot reporter tables now include a dedicated NO_COLOR row pointing at no-color.org.

Refs

  • Refs #40688 — same precedent (env-driven color suppression).

Fixes #40904

@williamdes

This comment was marked as resolved.

Copy link
Copy Markdown
Collaborator

@dgozman dgozman left a comment

Choose a reason for hiding this comment

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

Could you please file a new issue for this? All contributions to Playwright require an issue, and this PR agrees that the original issue was already fixed anyway.

Comment thread packages/playwright/src/reporters/base.ts Outdated
Comment thread packages/playwright/src/reporters/base.ts
@dgozman
Copy link
Copy Markdown
Collaborator

dgozman commented May 19, 2026

Let me close this until we figure out the exact issue this is fixing, and decide on the course of action there.

@williamdes

This comment was marked as outdated.

@dgozman dgozman reopened this May 20, 2026
@dgozman
Copy link
Copy Markdown
Collaborator

dgozman commented May 20, 2026

@williamdes Reopened. Could you please limit this PR to supporting NO_COLOR?

@williamdes williamdes force-pushed the fix/reporter-force-color-implies-non-tty branch from bb4ab57 to 23bcfdc Compare May 20, 2026 09:32
@williamdes williamdes changed the title fix(reporter): also gate isTTY on FORCE_COLOR=0 / NO_COLOR; honor NO_COLOR for colors fix(reporter): honor NO_COLOR in list/line/dot reporters May 20, 2026
Copy link
Copy Markdown
Author

@williamdes williamdes left a comment

Choose a reason for hiding this comment

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

I did a final review of the work and it looks okay by my review standards
Let me know

Comment thread packages/playwright/src/reporters/base.ts Outdated
Per https://no-color.org/, any non-empty NO_COLOR should disable
ANSI color output. The bundled chalk already honors it
internally, but code in base.ts that reads `useColors` won't —
so e.g. piping coloured test stdout through StripAnsiStream
only kicks in when FORCE_COLOR=0 is also set.

Add NO_COLOR to the existing useColors disabling branch so
NO_COLOR=1 alone disables colors, matching chalk's behavior and
the no-color.org convention.

isTTY is left unchanged — no-color.org makes no claims about
terminal shape, only about colors.

Test in reporter-list.spec.ts asserts NO_COLOR=1 strips ANSI
from test stdout, mirroring the existing FORCE_COLOR=0 test.
Docs in test-reporters-js.md gain a NO_COLOR row in all three
reporter tables (list / line / dot).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@williamdes williamdes force-pushed the fix/reporter-force-color-implies-non-tty branch from 23bcfdc to 2f9ed6e Compare May 20, 2026 10:25
@williamdes williamdes requested a review from dgozman May 20, 2026 10:29
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]: Reporter ignores NO_COLOR — colors and cursor codes still emitted with NO_COLOR=1

2 participants