6 files changed +79
-12
lines changed Original file line number Diff line number Diff line change @@ -24,18 +24,16 @@ module.exports = {
24
24
stream . getColorDepth ( ) > 2 : true ) ;
25
25
} ,
26
26
refresh ( ) {
27
- if ( process . stderr . isTTY ) {
28
- const hasColors = module . exports . shouldColorize ( process . stderr ) ;
29
- module . exports . blue = hasColors ? '\u001b[34m' : '' ;
30
- module . exports . green = hasColors ? '\u001b[32m' : '' ;
31
- module . exports . white = hasColors ? '\u001b[39m' : '' ;
32
- module . exports . yellow = hasColors ? '\u001b[33m' : '' ;
33
- module . exports . red = hasColors ? '\u001b[31m' : '' ;
34
- module . exports . gray = hasColors ? '\u001b[90m' : '' ;
35
- module . exports . clear = hasColors ? '\u001bc' : '' ;
36
- module . exports . reset = hasColors ? '\u001b[0m' : '' ;
37
- module . exports . hasColors = hasColors ;
38
- }
27
+ const hasColors = module . exports . shouldColorize ( process . stderr ) ;
28
+ module . exports . blue = hasColors ? '\u001b[34m' : '' ;
29
+ module . exports . green = hasColors ? '\u001b[32m' : '' ;
30
+ module . exports . white = hasColors ? '\u001b[39m' : '' ;
31
+ module . exports . yellow = hasColors ? '\u001b[33m' : '' ;
32
+ module . exports . red = hasColors ? '\u001b[31m' : '' ;
33
+ module . exports . gray = hasColors ? '\u001b[90m' : '' ;
34
+ module . exports . clear = hasColors ? '\u001bc' : '' ;
35
+ module . exports . reset = hasColors ? '\u001b[0m' : '' ;
36
+ module . exports . hasColors = hasColors ;
39
37
} ,
40
38
} ;
41
39
Original file line number Diff line number Diff line change
1
+ import assert from 'node:assert/strict'
2
+ import { test } from 'node:test'
3
+
4
+ test ( 'failing assertion' , ( ) => {
5
+ assert . strictEqual ( '!Hello World' , 'Hello World!' )
6
+ } )
Original file line number Diff line number Diff line change
1
+ [31m✖ failing assertion [90m(*ms)[39m[39m
2
+ [AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
3
+ [32mactual[39m [31mexpected[39m
4
+
5
+ [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
6
+ ] {
7
+ generatedMessage: [33mtrue[39m,
8
+ code: [32m'ERR_ASSERTION'[39m,
9
+ actual: [32m'!Hello World'[39m,
10
+ expected: [32m'Hello World!'[39m,
11
+ operator: [32m'strictEqual'[39m
12
+ }
13
+
14
+ [34mℹ tests 1[39m
15
+ [34mℹ suites 0[39m
16
+ [34mℹ pass 0[39m
17
+ [34mℹ fail 1[39m
18
+ [34mℹ cancelled 0[39m
19
+ [34mℹ skipped 0[39m
20
+ [34mℹ todo 0[39m
21
+ [34mℹ duration_ms *[39m
22
+
23
+ [31m✖ failing tests:[39m
24
+
25
+ *
26
+ [31m✖ failing assertion [90m(*ms)[39m[39m
27
+ [AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
28
+ [32mactual[39m [31mexpected[39m
29
+
30
+ [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
31
+ ] {
32
+ generatedMessage: [33mtrue[39m,
33
+ code: [32m'ERR_ASSERTION'[39m,
34
+ actual: [32m'!Hello World'[39m,
35
+ expected: [32m'Hello World!'[39m,
36
+ operator: [32m'strictEqual'[39m
37
+ }
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ process . env . FORCE_COLOR = 1 ;
4
+
5
+ const test = require ( 'node:test' ) ;
6
+ test ( 'passing test' , ( ) => { } ) ;
Original file line number Diff line number Diff line change
1
+ [32m✔ passing test [90m(*ms)[39m[39m
2
+ [34mℹ tests 1[39m
3
+ [34mℹ suites 0[39m
4
+ [34mℹ pass 1[39m
5
+ [34mℹ fail 0[39m
6
+ [34mℹ cancelled 0[39m
7
+ [34mℹ skipped 0[39m
8
+ [34mℹ todo 0[39m
9
+ [34mℹ duration_ms *[39m
Original file line number Diff line number Diff line change @@ -203,6 +203,17 @@ const tests = [
203
203
name : 'test-runner/output/arbitrary-output.js' ,
204
204
flags : [ '--test-reporter=tap' ] ,
205
205
} ,
206
+ {
207
+ name : 'test-runner/output/non-tty-forced-color-output.js' ,
208
+ flags : [ '--test-reporter=spec' ] ,
209
+ transform : specTransform ,
210
+ } ,
211
+ canColorize ? {
212
+ name : 'test-runner/output/assertion-color-tty.mjs' ,
213
+ flags : [ '--test' , '--stack-trace-limit=0' ] ,
214
+ transform : specTransform ,
215
+ tty : true ,
216
+ } : false ,
206
217
{
207
218
name : 'test-runner/output/async-test-scheduling.mjs' ,
208
219
flags : [ '--test-reporter=tap' ] ,
0 commit comments