@@ -107,6 +107,7 @@ export class Task extends EventTarget {
107107 this . dispatchEvent ( createBenchEvent ( 'start' , this ) )
108108 await this . bench . opts . setup ?.( this , 'run' )
109109 const { error, samples : latencySamples } = ( await this . benchmark (
110+ 'run' ,
110111 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
111112 this . bench . opts . time ! ,
112113 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -142,6 +143,7 @@ export class Task extends EventTarget {
142143 )
143144
144145 const { error, samples : latencySamples } = this . benchmarkSync (
146+ 'run' ,
145147 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
146148 this . bench . opts . time ! ,
147149 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -170,6 +172,7 @@ export class Task extends EventTarget {
170172 this . dispatchEvent ( createBenchEvent ( 'warmup' , this ) )
171173 await this . bench . opts . setup ?.( this , 'warmup' )
172174 const { error } = ( await this . benchmark (
175+ 'warmup' ,
173176 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
174177 this . bench . opts . warmupTime ! ,
175178 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -198,6 +201,7 @@ export class Task extends EventTarget {
198201 )
199202
200203 const { error } = this . benchmarkSync (
204+ 'warmup' ,
201205 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
202206 this . bench . opts . warmupTime ! ,
203207 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -214,12 +218,13 @@ export class Task extends EventTarget {
214218 }
215219
216220 private async benchmark (
221+ mode : 'run' | 'warmup' ,
217222 time : number ,
218223 iterations : number
219224 ) : Promise < { error ?: unknown ; samples ?: number [ ] } > {
220225 if ( this . fnOpts . beforeAll != null ) {
221226 try {
222- await this . fnOpts . beforeAll . call ( this )
227+ await this . fnOpts . beforeAll . call ( this , mode )
223228 } catch ( error ) {
224229 return { error }
225230 }
@@ -230,7 +235,7 @@ export class Task extends EventTarget {
230235 const samples : number [ ] = [ ]
231236 const benchmarkTask = async ( ) => {
232237 if ( this . fnOpts . beforeEach != null ) {
233- await this . fnOpts . beforeEach . call ( this )
238+ await this . fnOpts . beforeEach . call ( this , mode )
234239 }
235240
236241 let taskTime = 0 // ms;
@@ -254,7 +259,7 @@ export class Task extends EventTarget {
254259 totalTime += taskTime
255260
256261 if ( this . fnOpts . afterEach != null ) {
257- await this . fnOpts . afterEach . call ( this )
262+ await this . fnOpts . afterEach . call ( this , mode )
258263 }
259264 }
260265
@@ -282,7 +287,7 @@ export class Task extends EventTarget {
282287
283288 if ( this . fnOpts . afterAll != null ) {
284289 try {
285- await this . fnOpts . afterAll . call ( this )
290+ await this . fnOpts . afterAll . call ( this , mode )
286291 } catch ( error ) {
287292 return { error }
288293 }
@@ -291,12 +296,13 @@ export class Task extends EventTarget {
291296 }
292297
293298 private benchmarkSync (
299+ mode : 'run' | 'warmup' ,
294300 time : number ,
295301 iterations : number
296302 ) : { error ?: unknown ; samples ?: number [ ] } {
297303 if ( this . fnOpts . beforeAll != null ) {
298304 try {
299- const beforeAllResult = this . fnOpts . beforeAll . call ( this )
305+ const beforeAllResult = this . fnOpts . beforeAll . call ( this , mode )
300306 invariant (
301307 ! isPromiseLike ( beforeAllResult ) ,
302308 '`beforeAll` function must be sync when using `runSync()`'
@@ -311,7 +317,7 @@ export class Task extends EventTarget {
311317 const samples : number [ ] = [ ]
312318 const benchmarkTask = ( ) => {
313319 if ( this . fnOpts . beforeEach != null ) {
314- const beforeEachResult = this . fnOpts . beforeEach . call ( this )
320+ const beforeEachResult = this . fnOpts . beforeEach . call ( this , mode )
315321 invariant (
316322 ! isPromiseLike ( beforeEachResult ) ,
317323 '`beforeEach` function must be sync when using `runSync()`'
@@ -336,7 +342,7 @@ export class Task extends EventTarget {
336342 totalTime += taskTime
337343
338344 if ( this . fnOpts . afterEach != null ) {
339- const afterEachResult = this . fnOpts . afterEach . call ( this )
345+ const afterEachResult = this . fnOpts . afterEach . call ( this , mode )
340346 invariant (
341347 ! isPromiseLike ( afterEachResult ) ,
342348 '`afterEach` function must be sync when using `runSync()`'
@@ -358,7 +364,7 @@ export class Task extends EventTarget {
358364
359365 if ( this . fnOpts . afterAll != null ) {
360366 try {
361- const afterAllResult = this . fnOpts . afterAll . call ( this )
367+ const afterAllResult = this . fnOpts . afterAll . call ( this , mode )
362368 invariant (
363369 ! isPromiseLike ( afterAllResult ) ,
364370 '`afterAll` function must be sync when using `runSync()`'
0 commit comments