@@ -14,19 +14,11 @@ const {
14
14
const assert = require ( 'assert' ) ;
15
15
const Transform = require ( 'internal/streams/transform' ) ;
16
16
const { inspectWithNoCustomRetry } = require ( 'internal/errors' ) ;
17
- const { green , blue , red , white , gray , shouldColorize } = require ( 'internal/util/colors' ) ;
17
+ const colors = require ( 'internal/util/colors' ) ;
18
18
const { kSubtestsFailed } = require ( 'internal/test_runner/test' ) ;
19
19
const { getCoverageReport } = require ( 'internal/test_runner/utils' ) ;
20
20
const { relative } = require ( 'path' ) ;
21
21
22
- const inspectOptions = { __proto__ : null , colors : shouldColorize ( process . stdout ) , breakLength : Infinity } ;
23
-
24
- const colors = {
25
- '__proto__' : null ,
26
- 'test:fail' : red ,
27
- 'test:pass' : green ,
28
- 'test:diagnostic' : blue ,
29
- } ;
30
22
const symbols = {
31
23
'__proto__' : null ,
32
24
'test:fail' : '\u2716 ' ,
@@ -42,9 +34,19 @@ class SpecReporter extends Transform {
42
34
#indentMemo = new SafeMap ( ) ;
43
35
#failedTests = [ ] ;
44
36
#cwd = process . cwd ( ) ;
37
+ #inspectOptions;
38
+ #colors;
45
39
46
40
constructor ( ) {
47
41
super ( { __proto__ : null , writableObjectMode : true } ) ;
42
+ colors . refresh ( ) ;
43
+ this . #inspectOptions = { __proto__ : null , colors : colors . shouldColorize ( process . stdout ) , breakLength : Infinity } ;
44
+ this . #colors = {
45
+ '__proto__' : null ,
46
+ 'test:fail' : colors . red ,
47
+ 'test:pass' : colors . green ,
48
+ 'test:diagnostic' : colors . blue ,
49
+ } ;
48
50
}
49
51
50
52
#indent( nesting ) {
@@ -62,15 +64,15 @@ class SpecReporter extends Transform {
62
64
const message = ArrayPrototypeJoin (
63
65
RegExpPrototypeSymbolSplit (
64
66
hardenRegExp ( / \r ? \n / ) ,
65
- inspectWithNoCustomRetry ( err , inspectOptions ) ,
67
+ inspectWithNoCustomRetry ( err , this . # inspectOptions) ,
66
68
) , `\n${ indent } ` ) ;
67
69
return `\n${ indent } ${ message } \n` ;
68
70
}
69
71
#formatTestReport( type , data , prefix = '' , indent = '' , hasChildren = false ) {
70
- let color = colors [ type ] ?? white ;
72
+ let color = this . # colors[ type ] ?? colors . white ;
71
73
let symbol = symbols [ type ] ?? ' ' ;
72
74
const { skip, todo } = data ;
73
- const duration_ms = data . details ?. duration_ms ? ` ${ gray } (${ data . details . duration_ms } ms)${ white } ` : '' ;
75
+ const duration_ms = data . details ?. duration_ms ? ` ${ colors . gray } (${ data . details . duration_ms } ms)${ colors . white } ` : '' ;
74
76
let title = `${ data . name } ${ duration_ms } ` ;
75
77
76
78
if ( skip !== undefined ) {
@@ -82,13 +84,13 @@ class SpecReporter extends Transform {
82
84
if ( hasChildren ) {
83
85
// If this test has had children - it was already reported, so slightly modify the output
84
86
const err = data . details ?. error ?. failureType === 'subtestsFailed' ? '' : error ;
85
- return `${ prefix } ${ indent } ${ color } ${ symbols [ 'arrow:right' ] } ${ white } ${ title } \n${ err } ` ;
87
+ return `${ prefix } ${ indent } ${ color } ${ symbols [ 'arrow:right' ] } ${ colors . white } ${ title } \n${ err } ` ;
86
88
}
87
89
if ( skip !== undefined ) {
88
- color = gray ;
90
+ color = colors . gray ;
89
91
symbol = symbols [ 'hyphen:minus' ] ;
90
92
}
91
- return `${ prefix } ${ indent } ${ color } ${ symbol } ${ title } ${ white } ${ error } ` ;
93
+ return `${ prefix } ${ indent } ${ color } ${ symbol } ${ title } ${ colors . white } ${ error } ` ;
92
94
}
93
95
#handleTestReportEvent( type , data ) {
94
96
const subtest = ArrayPrototypeShift ( this . #stack) ; // This is the matching `test:start` event
@@ -130,9 +132,9 @@ class SpecReporter extends Transform {
130
132
case 'test:stdout' :
131
133
return data . message ;
132
134
case 'test:diagnostic' :
133
- return `${ colors [ type ] } ${ this . #indent( data . nesting ) } ${ symbols [ type ] } ${ data . message } ${ white } \n` ;
135
+ return `${ this . # colors[ type ] } ${ this . #indent( data . nesting ) } ${ symbols [ type ] } ${ data . message } ${ colors . white } \n` ;
134
136
case 'test:coverage' :
135
- return getCoverageReport ( this . #indent( data . nesting ) , data . summary , symbols [ 'test:coverage' ] , blue , true ) ;
137
+ return getCoverageReport ( this . #indent( data . nesting ) , data . summary , symbols [ 'test:coverage' ] , colors . blue , true ) ;
136
138
}
137
139
}
138
140
_transform ( { type, data } , encoding , callback ) {
@@ -143,7 +145,7 @@ class SpecReporter extends Transform {
143
145
callback ( null , '' ) ;
144
146
return ;
145
147
}
146
- const results = [ `\n${ colors [ 'test:fail' ] } ${ symbols [ 'test:fail' ] } failing tests:${ white } \n` ] ;
148
+ const results = [ `\n${ this . # colors[ 'test:fail' ] } ${ symbols [ 'test:fail' ] } failing tests:${ colors . white } \n` ] ;
147
149
for ( let i = 0 ; i < this . #failedTests. length ; i ++ ) {
148
150
const test = this . #failedTests[ i ] ;
149
151
const relPath = relative ( this . #cwd, test . file ) ;
0 commit comments