@@ -14,6 +14,8 @@ const { Test } = require('internal/test_runner/test');
14
14
15
15
16
16
const testResources = new SafeMap ( ) ;
17
+ const root = new Test ( { name : '<root>' } ) ;
18
+ let wasRootSetup = false ;
17
19
18
20
function createProcessEventHandler ( eventName , rootTest ) {
19
21
return ( err ) => {
@@ -42,6 +44,9 @@ function createProcessEventHandler(eventName, rootTest) {
42
44
}
43
45
44
46
function setup ( root ) {
47
+ if ( wasRootSetup ) {
48
+ return root ;
49
+ }
45
50
const hook = createHook ( {
46
51
init ( asyncId , type , triggerAsyncId , resource ) {
47
52
if ( resource instanceof Test ) {
@@ -118,26 +123,26 @@ function setup(root) {
118
123
119
124
root . reporter . pipe ( process . stdout ) ;
120
125
root . reporter . version ( ) ;
126
+
127
+ wasRootSetup = true ;
121
128
return root ;
122
129
}
123
130
124
- const root = setup ( new Test ( { name : '<root>' } ) ) ;
125
-
126
131
function test ( name , options , fn ) {
127
- const subtest = this . createSubtest ( name , options , fn ) ;
132
+ const subtest = setup ( root ) . createSubtest ( name , options , fn ) ;
128
133
return subtest . start ( ) ;
129
134
}
130
135
131
136
function describe ( name , options , fn ) {
132
- const parent = testResources . get ( executionAsyncId ( ) ) || root ;
137
+ const parent = testResources . get ( executionAsyncId ( ) ) || setup ( root ) ;
133
138
const suite = parent . createSubSuite ( name , options , fn ) ;
134
139
if ( parent === root ) {
135
140
suite . run ( ) ;
136
141
}
137
142
}
138
143
139
144
function it ( name , options , fn ) {
140
- const parent = testResources . get ( executionAsyncId ( ) ) || root ;
145
+ const parent = testResources . get ( executionAsyncId ( ) ) || setup ( root ) ;
141
146
parent . createSubtest ( name , options , fn ) ;
142
147
}
143
148
0 commit comments