fix: don't call "afterAll" hooks, if suite was skipped (#2802)

This commit is contained in:
Vladimir 2023-02-03 18:57:31 +01:00 committed by GitHub
parent 5eeb6f3863
commit aa1aa4daa2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 8 deletions

View File

@ -270,14 +270,14 @@ export async function runSuite(suite: Suite, runner: VitestRunner) {
catch (e) {
failTask(suite.result, e)
}
}
try {
await callSuiteHook(suite, suite, 'afterAll', runner, [suite])
await callCleanupHooks(beforeAllCleanups)
}
catch (e) {
failTask(suite.result, e)
try {
await callSuiteHook(suite, suite, 'afterAll', runner, [suite])
await callCleanupHooks(beforeAllCleanups)
}
catch (e) {
failTask(suite.result, e)
}
}
suite.result.duration = now() - start

View File

@ -1,7 +1,23 @@
import { assert, describe, expect, it } from 'vitest'
import { afterAll, afterEach, assert, beforeAll, beforeEach, describe, expect, it } from 'vitest'
import { timeout } from '../src/timeout'
describe.skip('skipped suite', () => {
beforeAll(() => {
throw new Error('should not run')
})
beforeEach(() => {
throw new Error('should not run')
})
afterEach(() => {
throw new Error('should not run')
})
afterAll(() => {
throw new Error('should not run')
})
it('no fail as suite is skipped', () => {
assert.equal(Math.sqrt(4), 3)
})