Skip to content

Commit

Permalink
fix: check hook teardown return type, closes #2092
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Oct 5, 2022
1 parent 757199a commit cba3ff0
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/vitest/src/runtime/run.ts
Expand Up @@ -2,7 +2,7 @@ import { performance } from 'perf_hooks'
import limit from 'p-limit'
import type { BenchTask, Benchmark, BenchmarkResult, File, HookCleanupCallback, HookListener, ResolvedConfig, Suite, SuiteHooks, Task, TaskResult, TaskState, Test } from '../types'
import { vi } from '../integrations/vi'
import { clearTimeout, createDefer, getFullName, getWorkerState, hasFailed, hasTests, isBrowser, isNode, isRunningInBenchmark, partitionSuiteChildren, setTimeout, shuffle } from '../utils'
import { assertTypes, clearTimeout, createDefer, getFullName, getWorkerState, hasFailed, hasTests, isBrowser, isNode, isRunningInBenchmark, partitionSuiteChildren, setTimeout, shuffle } from '../utils'
import { getState, setState } from '../integrations/chai/jest-expect'
import { GLOBAL_EXPECT } from '../integrations/chai/constants'
import { takeCoverageInsideWorker } from '../integrations/coverage'
Expand Down Expand Up @@ -84,6 +84,15 @@ async function sendTasksUpdate() {
}
}

const callCleanupHooks = async (cleanups: HookCleanupCallback[]) => {
await Promise.all(cleanups.map(async (fn) => {
if (!fn)
return
assertTypes(fn, 'hook teardown', ['function'])
await fn()
}))
}

export async function runTest(test: Test) {
if (test.mode !== 'run') {
const { getSnapshotClient } = await import('../integrations/snapshot/chai')
Expand Down Expand Up @@ -157,7 +166,7 @@ export async function runTest(test: Test) {

try {
await callSuiteHook(test.suite, test, 'afterEach', [test.context, test.suite])
await Promise.all(beforeEachCleanups.map(i => i?.()))
await callCleanupHooks(beforeEachCleanups)
}
catch (e) {
test.result.state = 'fail'
Expand Down Expand Up @@ -264,7 +273,7 @@ export async function runSuite(suite: Suite) {
}

await callSuiteHook(suite, suite, 'afterAll', [suite])
await Promise.all(beforeAllCleanups.map(i => i?.()))
await callCleanupHooks(beforeAllCleanups)
}
catch (e) {
suite.result.state = 'fail'
Expand Down

0 comments on commit cba3ff0

Please sign in to comment.