|
5 | 5 | ArrayPrototypeFlatMap, |
6 | 6 | ArrayPrototypePush, |
7 | 7 | ArrayPrototypeReduce, |
| 8 | + ArrayPrototypeSome, |
8 | 9 | ObjectGetOwnPropertyDescriptor, |
9 | 10 | MathFloor, |
10 | 11 | MathMax, |
@@ -134,10 +135,18 @@ function tryBuiltinReporter(name) { |
134 | 135 | returnrequire(builtinPath); |
135 | 136 | } |
136 | 137 |
|
137 | | -asyncfunctiongetReportersMap(reporters,destinations,rootTest){ |
| 138 | +functionshouldColorizeTestFiles(rootTest){ |
| 139 | +// This function assumes only built-in destinations (stdout/stderr) supports coloring |
| 140 | +const{ reporters, destinations }=parseCommandLine(); |
| 141 | +returnArrayPrototypeSome(reporters,(_,index)=>{ |
| 142 | +constdestination=kBuiltinDestinations.get(destinations[index]); |
| 143 | +returndestination&&shouldColorize(destination); |
| 144 | +}); |
| 145 | +} |
| 146 | + |
| 147 | +asyncfunctiongetReportersMap(reporters,destinations){ |
138 | 148 | returnSafePromiseAllReturnArrayLike(reporters,async(name,i)=>{ |
139 | 149 | constdestination=kBuiltinDestinations.get(destinations[i])??createWriteStream(destinations[i]); |
140 | | -rootTest.harness.shouldColorizeTestFiles||=shouldColorize(destination); |
141 | 150 |
|
142 | 151 | // Load the test reporter passed to --test-reporter |
143 | 152 | letreporter=tryBuiltinReporter(name); |
@@ -172,12 +181,12 @@ async function getReportersMap(reporters, destinations, rootTest) { |
172 | 181 | } |
173 | 182 |
|
174 | 183 | constreporterScope=newAsyncResource('TestReporterScope'); |
175 | | -constsetupTestReporters=reporterScope.bind(async(rootTest)=>{ |
| 184 | +constsetupTestReporters=reporterScope.bind(async(rootReporter)=>{ |
176 | 185 | const{ reporters, destinations }=parseCommandLine(); |
177 | | -constreportersMap=awaitgetReportersMap(reporters,destinations,rootTest); |
| 186 | +constreportersMap=awaitgetReportersMap(reporters,destinations); |
178 | 187 | for(leti=0;i<reportersMap.length;i++){ |
179 | 188 | const{ reporter, destination }=reportersMap[i]; |
180 | | -compose(rootTest.reporter,reporter).pipe(destination); |
| 189 | +compose(rootReporter,reporter).pipe(destination); |
181 | 190 | } |
182 | 191 | }); |
183 | 192 |
|
@@ -428,5 +437,6 @@ module.exports = { |
428 | 437 | parseCommandLine, |
429 | 438 | reporterScope, |
430 | 439 | setupTestReporters, |
| 440 | + shouldColorizeTestFiles, |
431 | 441 | getCoverageReport, |
432 | 442 | }; |
0 commit comments