diff --git a/packages/runner/src/run.ts b/packages/runner/src/run.ts index abcde35cc281..7b26c2d7d30e 100644 --- a/packages/runner/src/run.ts +++ b/packages/runner/src/run.ts @@ -271,6 +271,26 @@ export async function runTest(test: Test | Custom, runner: VitestRunner): Promis failTask(test.result, e, runner.config.diffOptions) } + try { + await callTaskHooks(test, test.onFinished || [], 'stack') + } + catch (e) { + failTask(test.result, e, runner.config.diffOptions) + } + + if (test.result.state === 'fail') { + try { + await callTaskHooks( + test, + test.onFailed || [], + runner.config.sequence.hooks, + ) + } + catch (e) { + failTask(test.result, e, runner.config.diffOptions) + } + } + if (test.result.state === 'pass') { break } @@ -286,26 +306,6 @@ export async function runTest(test: Test | Custom, runner: VitestRunner): Promis } } - try { - await callTaskHooks(test, test.onFinished || [], 'stack') - } - catch (e) { - failTask(test.result, e, runner.config.diffOptions) - } - - if (test.result.state === 'fail') { - try { - await callTaskHooks( - test, - test.onFailed || [], - runner.config.sequence.hooks, - ) - } - catch (e) { - failTask(test.result, e, runner.config.diffOptions) - } - } - // if test is marked to be failed, flip the result if (test.fails) { if (test.result.state === 'pass') {