@@ -186,33 +186,26 @@ async function startSubtest(subtest) {
186
186
await subtest . start ( ) ;
187
187
}
188
188
189
- function test ( name , options , fn ) {
190
- const parent = testResources . get ( executionAsyncId ( ) ) || getGlobalRoot ( ) ;
191
- const subtest = parent . createSubtest ( Test , name , options , fn ) ;
192
- if ( ! ( parent instanceof Suite ) ) {
193
- return startSubtest ( subtest ) ;
194
- }
195
- }
196
-
197
- function runInParentContext ( Factory ) {
189
+ function runInParentContext ( Factory , addShorthands = true ) {
198
190
function run ( name , options , fn , overrides ) {
199
191
const parent = testResources . get ( executionAsyncId ( ) ) || getGlobalRoot ( ) ;
200
192
const subtest = parent . createSubtest ( Factory , name , options , fn , overrides ) ;
201
- if ( parent === getGlobalRoot ( ) ) {
202
- startSubtest ( subtest ) ;
193
+ if ( ! ( parent instanceof Suite ) ) {
194
+ return startSubtest ( subtest ) ;
203
195
}
204
196
}
205
197
206
- const cb = ( name , options , fn ) => {
207
- run ( name , options , fn ) ;
208
- } ;
198
+ const test = ( name , options , fn ) => run ( name , options , fn ) ;
199
+ if ( ! addShorthands ) {
200
+ return test ;
201
+ }
209
202
210
203
ArrayPrototypeForEach ( [ 'skip' , 'todo' , 'only' ] , ( keyword ) => {
211
- cb [ keyword ] = ( name , options , fn ) => {
204
+ test [ keyword ] = ( name , options , fn ) => {
212
205
run ( name , options , fn , { [ keyword ] : true } ) ;
213
206
} ;
214
207
} ) ;
215
- return cb ;
208
+ return test ;
216
209
}
217
210
218
211
function hook ( hook ) {
@@ -224,7 +217,7 @@ function hook(hook) {
224
217
225
218
module . exports = {
226
219
createTestTree,
227
- test,
220
+ test : runInParentContext ( Test , false ) ,
228
221
describe : runInParentContext ( Suite ) ,
229
222
it : runInParentContext ( ItTest ) ,
230
223
before : hook ( 'before' ) ,
0 commit comments