11'use strict' ;
22const {
33 ArrayPrototypeForEach,
4+ PromiseResolve,
45 SafeMap,
56} = primordials ;
67const {
@@ -185,31 +186,27 @@ async function startSubtest(subtest) {
185186 await subtest . start ( ) ;
186187}
187188
188- function test ( name , options , fn ) {
189- const parent = testResources . get ( executionAsyncId ( ) ) || getGlobalRoot ( ) ;
190- const subtest = parent . createSubtest ( Test , name , options , fn ) ;
191- return startSubtest ( subtest ) ;
192- }
193-
194- function runInParentContext ( Factory ) {
189+ function runInParentContext ( Factory , addShorthands = true ) {
195190 function run ( name , options , fn , overrides ) {
196191 const parent = testResources . get ( executionAsyncId ( ) ) || getGlobalRoot ( ) ;
197192 const subtest = parent . createSubtest ( Factory , name , options , fn , overrides ) ;
198- if ( parent === getGlobalRoot ( ) ) {
199- startSubtest ( subtest ) ;
193+ if ( ! ( parent instanceof Suite ) ) {
194+ return startSubtest ( subtest ) ;
200195 }
196+ return PromiseResolve ( ) ;
201197 }
202198
203- const cb = ( name , options , fn ) => {
204- run ( name , options , fn ) ;
205- } ;
199+ const test = ( name , options , fn ) => run ( name , options , fn ) ;
200+ if ( ! addShorthands ) {
201+ return test ;
202+ }
206203
207204 ArrayPrototypeForEach ( [ 'skip' , 'todo' , 'only' ] , ( keyword ) => {
208- cb [ keyword ] = ( name , options , fn ) => {
205+ test [ keyword ] = ( name , options , fn ) => {
209206 run ( name , options , fn , { [ keyword ] : true } ) ;
210207 } ;
211208 } ) ;
212- return cb ;
209+ return test ;
213210}
214211
215212function hook ( hook ) {
@@ -221,7 +218,7 @@ function hook(hook) {
221218
222219module . exports = {
223220 createTestTree,
224- test,
221+ test : runInParentContext ( Test , false ) ,
225222 describe : runInParentContext ( Suite ) ,
226223 it : runInParentContext ( Test ) ,
227224 before : hook ( 'before' ) ,
0 commit comments