|
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 | return require(builtinPath); |
135 | 136 | } |
136 | 137 |
|
137 | | -async function getReportersMap(reporters, destinations, rootTest) { |
| 138 | +function shouldColorizeTestFiles(rootTest) { |
| 139 | + // This function assumes only built-in destinations (stdout/stderr) supports coloring |
| 140 | + const { reporters, destinations } = parseCommandLine(); |
| 141 | + return ArrayPrototypeSome(reporters, (_, index) => { |
| 142 | + const destination = kBuiltinDestinations.get(destinations[index]); |
| 143 | + return destination && shouldColorize(destination); |
| 144 | + }); |
| 145 | +} |
| 146 | + |
| 147 | +async function getReportersMap(reporters, destinations) { |
138 | 148 | return SafePromiseAllReturnArrayLike(reporters, async (name, i) => { |
139 | 149 | const destination = 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 | let reporter = tryBuiltinReporter(name); |
@@ -172,12 +181,12 @@ async function getReportersMap(reporters, destinations, rootTest) { |
172 | 181 | } |
173 | 182 |
|
174 | 183 | const reporterScope = new AsyncResource('TestReporterScope'); |
175 | | -const setupTestReporters = reporterScope.bind(async (rootTest) => { |
| 184 | +const setupTestReporters = reporterScope.bind(async (rootReporter) => { |
176 | 185 | const { reporters, destinations } = parseCommandLine(); |
177 | | - const reportersMap = await getReportersMap(reporters, destinations, rootTest); |
| 186 | + const reportersMap = await getReportersMap(reporters, destinations); |
178 | 187 | for (let i = 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