Skip to content

Commit

Permalink
fix: don't call "afterAll" hooks, if suite was skipped (#2802)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Feb 3, 2023
1 parent 5eeb6f3 commit aa1aa4d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
14 changes: 7 additions & 7 deletions packages/runner/src/run.ts
Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion 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)
})
Expand Down

0 comments on commit aa1aa4d

Please sign in to comment.