@@ -208,7 +208,7 @@ function setup(root) {
208208 } ;
209209 } ,
210210 counters : null ,
211- shouldColorizeTestFiles : false ,
211+ shouldColorizeTestFiles : shouldColorizeTestFiles ( globalOptions . destinations ) ,
212212 teardown : exitHandler ,
213213 snapshotManager : null ,
214214 } ;
@@ -218,48 +218,46 @@ function setup(root) {
218218}
219219
220220let globalRoot ;
221- let reportersSetup ;
222- function getGlobalRoot ( ) {
221+ let asyncBootstrap ;
222+ function lazyBootstrapRoot ( ) {
223223 if ( ! globalRoot ) {
224224 globalRoot = createTestTree ( { __proto__ : null , entryFile : process . argv ?. [ 1 ] } ) ;
225225 globalRoot . reporter . on ( 'test:fail' , ( data ) => {
226226 if ( data . todo === undefined || data . todo === false ) {
227227 process . exitCode = kGenericUserError ;
228228 }
229229 } ) ;
230- reportersSetup = setupTestReporters ( globalRoot . reporter ) ;
231- globalRoot . harness . shouldColorizeTestFiles ||= shouldColorizeTestFiles ( globalRoot ) ;
230+ asyncBootstrap = setupTestReporters ( globalRoot . reporter ) ;
232231 }
233232 return globalRoot ;
234233}
235234
236235async function startSubtest ( subtest ) {
237- if ( reportersSetup ) {
236+ if ( asyncBootstrap ) {
238237 // 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+ }
250247 }
251248
252249 await subtest . start ( ) ;
253250}
254251
255252function runInParentContext ( Factory ) {
256253 function run ( name , options , fn , overrides ) {
257- const parent = testResources . get ( executionAsyncId ( ) ) || getGlobalRoot ( ) ;
254+ const parent = testResources . get ( executionAsyncId ( ) ) || lazyBootstrapRoot ( ) ;
258255 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 ( ) ;
261258 }
262- return PromiseResolve ( ) ;
259+
260+ return startSubtest ( subtest ) ;
263261 }
264262
265263 const test = ( name , options , fn ) => {
@@ -286,7 +284,7 @@ function runInParentContext(Factory) {
286284
287285function hook ( hook ) {
288286 return ( fn , options ) => {
289- const parent = testResources . get ( executionAsyncId ( ) ) || getGlobalRoot ( ) ;
287+ const parent = testResources . get ( executionAsyncId ( ) ) || lazyBootstrapRoot ( ) ;
290288 parent . createHook ( hook , fn , {
291289 __proto__ : null ,
292290 ...options ,
0 commit comments