diff --git a/packages/runner/src/run.ts b/packages/runner/src/run.ts index e816f14d6224..205720cec14d 100644 --- a/packages/runner/src/run.ts +++ b/packages/runner/src/run.ts @@ -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 diff --git a/test/core/test/modes.test.ts b/test/core/test/modes.test.ts index 553ba038bc62..a2a0f0ec836e 100644 --- a/test/core/test/modes.test.ts +++ b/test/core/test/modes.test.ts @@ -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) })