@@ -31,6 +31,7 @@ class Runner extends Emittery {
31
31
this . boundCompareTestSnapshot = this . compareTestSnapshot . bind ( this ) ;
32
32
this . interrupted = false ;
33
33
this . snapshots = null ;
34
+ this . nextTaskIndex = 0 ;
34
35
this . tasks = {
35
36
after : [ ] ,
36
37
afterAlways : [ ] ,
@@ -76,6 +77,8 @@ class Runner extends Emittery {
76
77
} ) ;
77
78
}
78
79
80
+ metadata . taskIndex = this . nextTaskIndex ++ ;
81
+
79
82
const { args, buildTitle, implementations, rawTitle} = parseTestArgs ( testArgs ) ;
80
83
81
84
if ( this . checkSelectedByLineNumbers ) {
@@ -285,7 +288,7 @@ class Runner extends Emittery {
285
288
return result ;
286
289
}
287
290
288
- async runHooks ( tasks , contextRef , titleSuffix , testPassed ) {
291
+ async runHooks ( tasks , contextRef , { titleSuffix, testPassed, associatedTaskIndex } = { } ) {
289
292
const hooks = tasks . map ( task => new Runnable ( {
290
293
contextRef,
291
294
experiments : this . experiments ,
@@ -295,7 +298,7 @@ class Runner extends Emittery {
295
298
t => task . implementation . apply ( null , [ t ] . concat ( task . args ) ) ,
296
299
compareTestSnapshot : this . boundCompareTestSnapshot ,
297
300
updateSnapshots : this . updateSnapshots ,
298
- metadata : task . metadata ,
301
+ metadata : { ... task . metadata , associatedTaskIndex } ,
299
302
powerAssert : this . powerAssert ,
300
303
title : `${ task . title } ${ titleSuffix || '' } ` ,
301
304
isHook : true ,
@@ -326,7 +329,14 @@ class Runner extends Emittery {
326
329
327
330
async runTest ( task , contextRef ) {
328
331
const hookSuffix = ` for ${ task . title } ` ;
329
- let hooksOk = await this . runHooks ( this . tasks . beforeEach , contextRef , hookSuffix ) ;
332
+ let hooksOk = await this . runHooks (
333
+ this . tasks . beforeEach ,
334
+ contextRef ,
335
+ {
336
+ titleSuffix : hookSuffix ,
337
+ associatedTaskIndex : task . metadata . taskIndex
338
+ }
339
+ ) ;
330
340
331
341
let testOk = false ;
332
342
if ( hooksOk ) {
@@ -358,7 +368,14 @@ class Runner extends Emittery {
358
368
logs : result . logs
359
369
} ) ;
360
370
361
- hooksOk = await this . runHooks ( this . tasks . afterEach , contextRef , hookSuffix , testOk ) ;
371
+ hooksOk = await this . runHooks (
372
+ this . tasks . afterEach ,
373
+ contextRef ,
374
+ {
375
+ titleSuffix : hookSuffix ,
376
+ testPassed : testOk ,
377
+ associatedTaskIndex : task . metadata . taskIndex
378
+ } ) ;
362
379
} else {
363
380
this . emit ( 'stateChange' , {
364
381
type : 'test-failed' ,
@@ -372,7 +389,14 @@ class Runner extends Emittery {
372
389
}
373
390
}
374
391
375
- const alwaysOk = await this . runHooks ( this . tasks . afterEachAlways , contextRef , hookSuffix , testOk ) ;
392
+ const alwaysOk = await this . runHooks (
393
+ this . tasks . afterEachAlways ,
394
+ contextRef ,
395
+ {
396
+ titleSuffix : hookSuffix ,
397
+ testPassed : testOk ,
398
+ associatedTaskIndex : task . metadata . taskIndex
399
+ } ) ;
376
400
return alwaysOk && hooksOk && testOk ;
377
401
}
378
402
0 commit comments