@@ -14,6 +14,8 @@ const { Test } = require('internal/test_runner/test');
1414
1515
1616const testResources = new SafeMap ( ) ;
17+ const root = new Test ( { name : '<root>' } ) ;
18+ let wasRootSetup = false ;
1719
1820function createProcessEventHandler ( eventName , rootTest ) {
1921 return ( err ) => {
@@ -42,6 +44,9 @@ function createProcessEventHandler(eventName, rootTest) {
4244}
4345
4446function setup ( root ) {
47+ if ( wasRootSetup ) {
48+ return root ;
49+ }
4550 const hook = createHook ( {
4651 init ( asyncId , type , triggerAsyncId , resource ) {
4752 if ( resource instanceof Test ) {
@@ -118,26 +123,26 @@ function setup(root) {
118123
119124 root . reporter . pipe ( process . stdout ) ;
120125 root . reporter . version ( ) ;
126+
127+ wasRootSetup = true ;
121128 return root ;
122129}
123130
124- const root = setup ( new Test ( { name : '<root>' } ) ) ;
125-
126131function test ( name , options , fn ) {
127- const subtest = this . createSubtest ( name , options , fn ) ;
132+ const subtest = setup ( root ) . createSubtest ( name , options , fn ) ;
128133 return subtest . start ( ) ;
129134}
130135
131136function describe ( name , options , fn ) {
132- const parent = testResources . get ( executionAsyncId ( ) ) || root ;
137+ const parent = testResources . get ( executionAsyncId ( ) ) || setup ( root ) ;
133138 const suite = parent . createSubSuite ( name , options , fn ) ;
134139 if ( parent === root ) {
135140 suite . run ( ) ;
136141 }
137142}
138143
139144function it ( name , options , fn ) {
140- const parent = testResources . get ( executionAsyncId ( ) ) || root ;
145+ const parent = testResources . get ( executionAsyncId ( ) ) || setup ( root ) ;
141146 parent . createSubtest ( name , options , fn ) ;
142147}
143148
0 commit comments