|
5 | 5 | ArrayPrototypeFlatMap,
|
6 | 6 | ArrayPrototypePush,
|
7 | 7 | ArrayPrototypeReduce,
|
| 8 | + ArrayPrototypeSome, |
8 | 9 | ObjectGetOwnPropertyDescriptor,
|
9 | 10 | MathFloor,
|
10 | 11 | MathMax,
|
@@ -128,10 +129,18 @@ function tryBuiltinReporter(name) {
|
128 | 129 | return require(builtinPath);
|
129 | 130 | }
|
130 | 131 |
|
131 |
| -async function getReportersMap(reporters, destinations, rootTest) { |
| 132 | +function shouldColorizeTestFiles(rootTest) { |
| 133 | + // This function assumes only built-in destinations (stdout/stderr) supports coloring |
| 134 | + const { reporters, destinations } = parseCommandLine(); |
| 135 | + return ArrayPrototypeSome(reporters, (_, index) => { |
| 136 | + const destination = kBuiltinDestinations.get(destinations[index]); |
| 137 | + return destination && shouldColorize(destination); |
| 138 | + }); |
| 139 | +} |
| 140 | + |
| 141 | +async function getReportersMap(reporters, destinations) { |
132 | 142 | return SafePromiseAllReturnArrayLike(reporters, async (name, i) => {
|
133 | 143 | const destination = kBuiltinDestinations.get(destinations[i]) ?? createWriteStream(destinations[i]);
|
134 |
| - rootTest.harness.shouldColorizeTestFiles ||= shouldColorize(destination); |
135 | 144 |
|
136 | 145 | // Load the test reporter passed to --test-reporter
|
137 | 146 | let reporter = tryBuiltinReporter(name);
|
@@ -166,12 +175,12 @@ async function getReportersMap(reporters, destinations, rootTest) {
|
166 | 175 | }
|
167 | 176 |
|
168 | 177 | const reporterScope = new AsyncResource('TestReporterScope');
|
169 |
| -const setupTestReporters = reporterScope.bind(async (rootTest) => { |
| 178 | +const setupTestReporters = reporterScope.bind(async (rootReporter) => { |
170 | 179 | const { reporters, destinations } = parseCommandLine();
|
171 |
| - const reportersMap = await getReportersMap(reporters, destinations, rootTest); |
| 180 | + const reportersMap = await getReportersMap(reporters, destinations); |
172 | 181 | for (let i = 0; i < reportersMap.length; i++) {
|
173 | 182 | const { reporter, destination } = reportersMap[i];
|
174 |
| - compose(rootTest.reporter, reporter).pipe(destination); |
| 183 | + compose(rootReporter, reporter).pipe(destination); |
175 | 184 | }
|
176 | 185 | });
|
177 | 186 |
|
@@ -421,5 +430,6 @@ module.exports = {
|
421 | 430 | parseCommandLine,
|
422 | 431 | reporterScope,
|
423 | 432 | setupTestReporters,
|
| 433 | + shouldColorizeTestFiles, |
424 | 434 | getCoverageReport,
|
425 | 435 | };
|
0 commit comments