-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib: ensure FORCE_COLOR forces color output in non-TTY environments #55404
Changes from all commits
13b34d2
398da0f
e746328
b74485e
dd82e49
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import assert from 'node:assert/strict' | ||
import { test } from 'node:test' | ||
|
||
test('failing assertion', () => { | ||
assert.strictEqual('!Hello World', 'Hello World!') | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[31m✖ failing assertion [90m(*ms)[39m[39m | ||
[AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: | ||
[32mactual[39m [31mexpected[39m | ||
|
||
[39m'[39m[32m![39m[39mH[39m[39me[39m[39ml[39m[39ml[39m[39mo[39m[39m [39m[39mW[39m[39mo[39m[39mr[39m[39ml[39m[39md[39m[31m![39m[39m'[39m | ||
] { | ||
generatedMessage: [33mtrue[39m, | ||
code: [32m'ERR_ASSERTION'[39m, | ||
actual: [32m'!Hello World'[39m, | ||
expected: [32m'Hello World!'[39m, | ||
operator: [32m'strictEqual'[39m | ||
} | ||
|
||
[34mℹ tests 1[39m | ||
[34mℹ suites 0[39m | ||
[34mℹ pass 0[39m | ||
[34mℹ fail 1[39m | ||
[34mℹ cancelled 0[39m | ||
[34mℹ skipped 0[39m | ||
[34mℹ todo 0[39m | ||
[34mℹ duration_ms *[39m | ||
|
||
[31m✖ failing tests:[39m | ||
|
||
* | ||
[31m✖ failing assertion [90m(*ms)[39m[39m | ||
[AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: | ||
[32mactual[39m [31mexpected[39m | ||
|
||
[39m'[39m[32m![39m[39mH[39m[39me[39m[39ml[39m[39ml[39m[39mo[39m[39m [39m[39mW[39m[39mo[39m[39mr[39m[39ml[39m[39md[39m[31m![39m[39m'[39m | ||
] { | ||
generatedMessage: [33mtrue[39m, | ||
code: [32m'ERR_ASSERTION'[39m, | ||
actual: [32m'!Hello World'[39m, | ||
expected: [32m'Hello World!'[39m, | ||
operator: [32m'strictEqual'[39m | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict'; | ||
|
||
process.env.FORCE_COLOR = 1; | ||
|
||
const test = require('node:test'); | ||
test('passing test', () => {}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[32m✔ passing test [90m(*ms)[39m[39m | ||
[34mℹ tests 1[39m | ||
[34mℹ suites 0[39m | ||
[34mℹ pass 1[39m | ||
[34mℹ fail 0[39m | ||
[34mℹ cancelled 0[39m | ||
[34mℹ skipped 0[39m | ||
[34mℹ todo 0[39m | ||
[34mℹ duration_ms *[39m |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -203,6 +203,16 @@ const tests = [ | |||||||
name: 'test-runner/output/arbitrary-output.js', | ||||||||
flags: ['--test-reporter=tap'], | ||||||||
}, | ||||||||
{ | ||||||||
name: 'test-runner/output/non-tty-forced-color-output.js', | ||||||||
transform: specTransform, | ||||||||
}, | ||||||||
canColorize ? { | ||||||||
name: 'test-runner/output/assertion-color-tty.mjs', | ||||||||
flags: ['--test', '--stack-trace-limit=0'], | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @cjihrig, I had to add the node/test/common/assertSnapshot.js Lines 7 to 9 in 4d6d7d6
to match colored stack traces also seems a little painful. Do you think it's acceptable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's fine IMO. |
||||||||
transform: specTransform, | ||||||||
tty: true, | ||||||||
} : false, | ||||||||
{ | ||||||||
name: 'test-runner/output/async-test-scheduling.mjs', | ||||||||
flags: ['--test-reporter=tap'], | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking and admittedly more verbose (and I know not introduced in this PR) but I'd generally prefer something like the following instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @jasnell, thanks for the review.
I don't have strong opinions on this specific case, but in general, I think the more readable, the better.
We would have some repetitions, but I think it would be worth it.
Up to you 🚀 If you want, I can use this PR to address this readability issue as well 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CI is green now, maybe consider doing a follow up PR (I agree with suggested change though).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, also because I have the impression that osx CI has been a little unstable in the last two days