@@ -2,7 +2,7 @@ import { performance } from 'perf_hooks'
22import limit from 'p-limit'
33import type { BenchTask , Benchmark , BenchmarkResult , File , HookCleanupCallback , HookListener , ResolvedConfig , Suite , SuiteHooks , Task , TaskResult , TaskState , Test } from '../types'
44import { vi } from '../integrations/vi'
5- import { clearTimeout , createDefer , getFullName , getWorkerState , hasFailed , hasTests , isBrowser , isNode , isRunningInBenchmark , partitionSuiteChildren , setTimeout , shuffle } from '../utils'
5+ import { assertTypes , clearTimeout , createDefer , getFullName , getWorkerState , hasFailed , hasTests , isBrowser , isNode , isRunningInBenchmark , partitionSuiteChildren , setTimeout , shuffle } from '../utils'
66import { getState , setState } from '../integrations/chai/jest-expect'
77import { GLOBAL_EXPECT } from '../integrations/chai/constants'
88import { takeCoverageInsideWorker } from '../integrations/coverage'
@@ -84,6 +84,15 @@ async function sendTasksUpdate() {
8484 }
8585}
8686
87+ const callCleanupHooks = async ( cleanups : HookCleanupCallback [ ] ) => {
88+ await Promise . all ( cleanups . map ( async ( fn ) => {
89+ if ( ! fn )
90+ return
91+ assertTypes ( fn , 'hook teardown' , [ 'function' ] )
92+ await fn ( )
93+ } ) )
94+ }
95+
8796export async function runTest ( test : Test ) {
8897 if ( test . mode !== 'run' ) {
8998 const { getSnapshotClient } = await import ( '../integrations/snapshot/chai' )
@@ -157,7 +166,7 @@ export async function runTest(test: Test) {
157166
158167 try {
159168 await callSuiteHook ( test . suite , test , 'afterEach' , [ test . context , test . suite ] )
160- await Promise . all ( beforeEachCleanups . map ( i => i ?. ( ) ) )
169+ await callCleanupHooks ( beforeEachCleanups )
161170 }
162171 catch ( e ) {
163172 test . result . state = 'fail'
@@ -264,7 +273,7 @@ export async function runSuite(suite: Suite) {
264273 }
265274
266275 await callSuiteHook ( suite , suite , 'afterAll' , [ suite ] )
267- await Promise . all ( beforeAllCleanups . map ( i => i ?. ( ) ) )
276+ await callCleanupHooks ( beforeAllCleanups )
268277 }
269278 catch ( e ) {
270279 suite . result . state = 'fail'
0 commit comments