@@ -107,6 +107,7 @@ export class Task extends EventTarget {
107
107
this . dispatchEvent ( createBenchEvent ( 'start' , this ) )
108
108
await this . bench . opts . setup ?.( this , 'run' )
109
109
const { error, samples : latencySamples } = ( await this . benchmark (
110
+ 'run' ,
110
111
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
111
112
this . bench . opts . time ! ,
112
113
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -142,6 +143,7 @@ export class Task extends EventTarget {
142
143
)
143
144
144
145
const { error, samples : latencySamples } = this . benchmarkSync (
146
+ 'run' ,
145
147
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
146
148
this . bench . opts . time ! ,
147
149
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -170,6 +172,7 @@ export class Task extends EventTarget {
170
172
this . dispatchEvent ( createBenchEvent ( 'warmup' , this ) )
171
173
await this . bench . opts . setup ?.( this , 'warmup' )
172
174
const { error } = ( await this . benchmark (
175
+ 'warmup' ,
173
176
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
174
177
this . bench . opts . warmupTime ! ,
175
178
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -198,6 +201,7 @@ export class Task extends EventTarget {
198
201
)
199
202
200
203
const { error } = this . benchmarkSync (
204
+ 'warmup' ,
201
205
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
202
206
this . bench . opts . warmupTime ! ,
203
207
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -214,12 +218,13 @@ export class Task extends EventTarget {
214
218
}
215
219
216
220
private async benchmark (
221
+ mode : 'run' | 'warmup' ,
217
222
time : number ,
218
223
iterations : number
219
224
) : Promise < { error ?: unknown ; samples ?: number [ ] } > {
220
225
if ( this . fnOpts . beforeAll != null ) {
221
226
try {
222
- await this . fnOpts . beforeAll . call ( this )
227
+ await this . fnOpts . beforeAll . call ( this , mode )
223
228
} catch ( error ) {
224
229
return { error }
225
230
}
@@ -230,7 +235,7 @@ export class Task extends EventTarget {
230
235
const samples : number [ ] = [ ]
231
236
const benchmarkTask = async ( ) => {
232
237
if ( this . fnOpts . beforeEach != null ) {
233
- await this . fnOpts . beforeEach . call ( this )
238
+ await this . fnOpts . beforeEach . call ( this , mode )
234
239
}
235
240
236
241
let taskTime = 0 // ms;
@@ -254,7 +259,7 @@ export class Task extends EventTarget {
254
259
totalTime += taskTime
255
260
256
261
if ( this . fnOpts . afterEach != null ) {
257
- await this . fnOpts . afterEach . call ( this )
262
+ await this . fnOpts . afterEach . call ( this , mode )
258
263
}
259
264
}
260
265
@@ -282,7 +287,7 @@ export class Task extends EventTarget {
282
287
283
288
if ( this . fnOpts . afterAll != null ) {
284
289
try {
285
- await this . fnOpts . afterAll . call ( this )
290
+ await this . fnOpts . afterAll . call ( this , mode )
286
291
} catch ( error ) {
287
292
return { error }
288
293
}
@@ -291,12 +296,13 @@ export class Task extends EventTarget {
291
296
}
292
297
293
298
private benchmarkSync (
299
+ mode : 'run' | 'warmup' ,
294
300
time : number ,
295
301
iterations : number
296
302
) : { error ?: unknown ; samples ?: number [ ] } {
297
303
if ( this . fnOpts . beforeAll != null ) {
298
304
try {
299
- const beforeAllResult = this . fnOpts . beforeAll . call ( this )
305
+ const beforeAllResult = this . fnOpts . beforeAll . call ( this , mode )
300
306
invariant (
301
307
! isPromiseLike ( beforeAllResult ) ,
302
308
'`beforeAll` function must be sync when using `runSync()`'
@@ -311,7 +317,7 @@ export class Task extends EventTarget {
311
317
const samples : number [ ] = [ ]
312
318
const benchmarkTask = ( ) => {
313
319
if ( this . fnOpts . beforeEach != null ) {
314
- const beforeEachResult = this . fnOpts . beforeEach . call ( this )
320
+ const beforeEachResult = this . fnOpts . beforeEach . call ( this , mode )
315
321
invariant (
316
322
! isPromiseLike ( beforeEachResult ) ,
317
323
'`beforeEach` function must be sync when using `runSync()`'
@@ -336,7 +342,7 @@ export class Task extends EventTarget {
336
342
totalTime += taskTime
337
343
338
344
if ( this . fnOpts . afterEach != null ) {
339
- const afterEachResult = this . fnOpts . afterEach . call ( this )
345
+ const afterEachResult = this . fnOpts . afterEach . call ( this , mode )
340
346
invariant (
341
347
! isPromiseLike ( afterEachResult ) ,
342
348
'`afterEach` function must be sync when using `runSync()`'
@@ -358,7 +364,7 @@ export class Task extends EventTarget {
358
364
359
365
if ( this . fnOpts . afterAll != null ) {
360
366
try {
361
- const afterAllResult = this . fnOpts . afterAll . call ( this )
367
+ const afterAllResult = this . fnOpts . afterAll . call ( this , mode )
362
368
invariant (
363
369
! isPromiseLike ( afterAllResult ) ,
364
370
'`afterAll` function must be sync when using `runSync()`'
0 commit comments