@@ -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 ,
0 commit comments