Skip to content

Commit aa1aa4d

Browse files
authored
fix: don't call "afterAll" hooks, if suite was skipped (#2802)
1 parent 5eeb6f3 commit aa1aa4d

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

packages/runner/src/run.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,14 @@ export async function runSuite(suite: Suite, runner: VitestRunner) {
270270
catch (e) {
271271
failTask(suite.result, e)
272272
}
273-
}
274273

275-
try {
276-
await callSuiteHook(suite, suite, 'afterAll', runner, [suite])
277-
await callCleanupHooks(beforeAllCleanups)
278-
}
279-
catch (e) {
280-
failTask(suite.result, e)
274+
try {
275+
await callSuiteHook(suite, suite, 'afterAll', runner, [suite])
276+
await callCleanupHooks(beforeAllCleanups)
277+
}
278+
catch (e) {
279+
failTask(suite.result, e)
280+
}
281281
}
282282

283283
suite.result.duration = now() - start

test/core/test/modes.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
1-
import { assert, describe, expect, it } from 'vitest'
1+
import { afterAll, afterEach, assert, beforeAll, beforeEach, describe, expect, it } from 'vitest'
22
import { timeout } from '../src/timeout'
33

44
describe.skip('skipped suite', () => {
5+
beforeAll(() => {
6+
throw new Error('should not run')
7+
})
8+
9+
beforeEach(() => {
10+
throw new Error('should not run')
11+
})
12+
13+
afterEach(() => {
14+
throw new Error('should not run')
15+
})
16+
17+
afterAll(() => {
18+
throw new Error('should not run')
19+
})
20+
521
it('no fail as suite is skipped', () => {
622
assert.equal(Math.sqrt(4), 3)
723
})

0 commit comments

Comments
 (0)