+23
-29
lines changedFilter options
+23
-29
lines changed Original file line number Diff line number Diff line change
@@ -208,7 +208,7 @@ function setup(root) {
208
208
};
209
209
},
210
210
counters: null,
211
-
shouldColorizeTestFiles: false,
211
+
shouldColorizeTestFiles: shouldColorizeTestFiles(globalOptions.destinations),
212
212
teardown: exitHandler,
213
213
snapshotManager: null,
214
214
};
@@ -218,48 +218,46 @@ function setup(root) {
218
218
}
219
219
220
220
let globalRoot;
221
-
let reportersSetup;
222
-
function getGlobalRoot() {
221
+
let asyncBootstrap;
222
+
function lazyBootstrapRoot() {
223
223
if (!globalRoot) {
224
224
globalRoot = createTestTree({ __proto__: null, entryFile: process.argv?.[1] });
225
225
globalRoot.reporter.on('test:fail', (data) => {
226
226
if (data.todo === undefined || data.todo === false) {
227
227
process.exitCode = kGenericUserError;
228
228
}
229
229
});
230
-
reportersSetup = setupTestReporters(globalRoot.reporter);
231
-
globalRoot.harness.shouldColorizeTestFiles ||= shouldColorizeTestFiles(globalRoot);
230
+
asyncBootstrap = setupTestReporters(globalRoot.reporter);
232
231
}
233
232
return globalRoot;
234
233
}
235
234
236
235
async function startSubtest(subtest) {
237
-
if (reportersSetup) {
236
+
if (asyncBootstrap) {
238
237
// Only incur the overhead of awaiting the Promise once.
239
-
await reportersSetup;
240
-
reportersSetup = undefined;
241
-
}
242
-
243
-
const root = getGlobalRoot();
244
-
if (!root.harness.bootstrapComplete) {
245
-
root.harness.bootstrapComplete = true;
246
-
queueMicrotask(() => {
247
-
root.harness.allowTestsToRun = true;
248
-
root.processPendingSubtests();
249
-
});
238
+
await asyncBootstrap;
239
+
asyncBootstrap = undefined;
240
+
if (!subtest.root.harness.bootstrapComplete) {
241
+
subtest.root.harness.bootstrapComplete = true;
242
+
queueMicrotask(() => {
243
+
subtest.root.harness.allowTestsToRun = true;
244
+
subtest.root.processPendingSubtests();
245
+
});
246
+
}
250
247
}
251
248
252
249
await subtest.start();
253
250
}
254
251
255
252
function runInParentContext(Factory) {
256
253
function run(name, options, fn, overrides) {
257
-
const parent = testResources.get(executionAsyncId()) || getGlobalRoot();
254
+
const parent = testResources.get(executionAsyncId()) || lazyBootstrapRoot();
258
255
const subtest = parent.createSubtest(Factory, name, options, fn, overrides);
259
-
if (!(parent instanceof Suite)) {
260
-
return startSubtest(subtest);
256
+
if (parent instanceof Suite) {
257
+
return PromiseResolve();
261
258
}
262
-
return PromiseResolve();
259
+
260
+
return startSubtest(subtest);
263
261
}
264
262
265
263
const test = (name, options, fn) => {
@@ -286,7 +284,7 @@ function runInParentContext(Factory) {
286
284
287
285
function hook(hook) {
288
286
return (fn, options) => {
289
-
const parent = testResources.get(executionAsyncId()) || getGlobalRoot();
287
+
const parent = testResources.get(executionAsyncId()) || lazyBootstrapRoot();
290
288
parent.createHook(hook, fn, {
291
289
__proto__: null,
292
290
...options,
Original file line number Diff line number Diff line change
@@ -70,7 +70,6 @@ const {
70
70
convertStringToRegExp,
71
71
countCompletedTest,
72
72
kDefaultPattern,
73
-
shouldColorizeTestFiles,
74
73
} = require('internal/test_runner/utils');
75
74
const { Glob } = require('internal/fs/glob');
76
75
const { once } = require('events');
@@ -552,7 +551,6 @@ function run(options = kEmptyObject) {
552
551
}
553
552
554
553
const root = createTestTree({ __proto__: null, concurrency, timeout, signal });
555
-
root.harness.shouldColorizeTestFiles ||= shouldColorizeTestFiles(root);
556
554
557
555
if (process.env.NODE_TEST_CONTEXT !== undefined) {
558
556
process.emitWarning('node:test run() is being called recursively within a test file. skipping running files.');
Original file line number Diff line number Diff line change
@@ -75,7 +75,6 @@ const kHookFailure = 'hookFailed';
75
75
const kDefaultTimeout = null;
76
76
const noop = FunctionPrototype;
77
77
const kShouldAbort = Symbol('kShouldAbort');
78
-
const kFilename = process.argv?.[1];
79
78
const kHookNames = ObjectSeal(['before', 'after', 'beforeEach', 'afterEach']);
80
79
const kUnwrapErrors = new SafeSet()
81
80
.add(kTestCodeFailure).add(kHookFailure)
@@ -508,7 +507,7 @@ class Test extends AsyncResource {
508
507
this.diagnostic(warning);
509
508
}
510
509
511
-
if (loc === undefined || kFilename === undefined) {
510
+
if (loc === undefined) {
512
511
this.loc = undefined;
513
512
} else {
514
513
this.loc = {
Original file line number Diff line number Diff line change
@@ -131,10 +131,9 @@ function tryBuiltinReporter(name) {
131
131
return require(builtinPath);
132
132
}
133
133
134
-
function shouldColorizeTestFiles(rootTest) {
134
+
function shouldColorizeTestFiles(destinations) {
135
135
// This function assumes only built-in destinations (stdout/stderr) supports coloring
136
-
const { reporters, destinations } = parseCommandLine();
137
-
return ArrayPrototypeSome(reporters, (_, index) => {
136
+
return ArrayPrototypeSome(destinations, (_, index) => {
138
137
const destination = kBuiltinDestinations.get(destinations[index]);
139
138
return destination && shouldColorize(destination);
140
139
});
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4