diff --git a/packages/runner/src/run.ts b/packages/runner/src/run.ts index d03402e558fb..94b46684300d 100644 --- a/packages/runner/src/run.ts +++ b/packages/runner/src/run.ts @@ -236,6 +236,8 @@ export async function runTest(test: Test, runner: VitestRunner): Promise { await runner.onBeforeRunTask?.(test) if (test.mode !== 'run' && test.mode !== 'queued') { + updateTask('test-prepare', test, runner) + updateTask('test-finished', test, runner) return } diff --git a/packages/vitest/src/node/test-run.ts b/packages/vitest/src/node/test-run.ts index e98798ce9c34..3760f45ae372 100644 --- a/packages/vitest/src/node/test-run.ts +++ b/packages/vitest/src/node/test-run.ts @@ -107,17 +107,6 @@ export class TestRun { // we need to report everything manually await this.reportChildren(entity.children) } - else { - // skipped tests need to be reported manually once test module/suite has finished - for (const test of entity.children.tests('skipped')) { - if (test.task.result?.pending) { - // pending error tasks are reported normally - continue - } - await this.vitest.report('onTestCaseReady', test) - await this.vitest.report('onTestCaseResult', test) - } - } if (entity.type === 'module') { await this.vitest.report('onTestModuleEnd', entity) diff --git a/packages/vitest/src/utils/tasks.ts b/packages/vitest/src/utils/tasks.ts index 2cb3624b79fd..f7c5bac986dc 100644 --- a/packages/vitest/src/utils/tasks.ts +++ b/packages/vitest/src/utils/tasks.ts @@ -37,8 +37,8 @@ export function convertTasksToEvents(file: File, onTask?: (task: Task) => void): } else { onTask?.(task) - packs.push([task.id, task.result, task.meta]) - if (task.mode !== 'skip' && task.mode !== 'todo') { + if (suite.mode !== 'skip' && suite.mode !== 'todo') { + packs.push([task.id, task.result, task.meta]) events.push([task.id, 'test-prepare'], [task.id, 'test-finished']) } } diff --git a/test/reporters/tests/test-run.test.ts b/test/reporters/tests/test-run.test.ts index db0a4504f126..32ab7d631903 100644 --- a/test/reporters/tests/test-run.test.ts +++ b/test/reporters/tests/test-run.test.ts @@ -263,6 +263,52 @@ describe('TestCase', () => { `) }) + test('skipped test case in a different order', async () => { + const report = await run({ + 'example.test.ts': ts` + test.skip('skipped', () => {}); + test('running', () => {}); + `, + }) + + expect(report).toMatchInlineSnapshot(` + " + onTestModuleQueued (example.test.ts) + onTestModuleCollected (example.test.ts) + onTestModuleStart (example.test.ts) + onTestCaseReady (example.test.ts) |skipped| + onTestCaseResult (example.test.ts) |skipped| + onTestCaseReady (example.test.ts) |running| + onTestCaseResult (example.test.ts) |running| + onTestModuleEnd (example.test.ts)" + `) + }) + + test('skipped test case in a suite with a different order', async () => { + const report = await run({ + 'example.test.ts': ts` + describe('suite', () => { + test.skip('skipped', () => {}); + test('running', () => {}); + }) + `, + }) + + expect(report).toMatchInlineSnapshot(` + " + onTestModuleQueued (example.test.ts) + onTestModuleCollected (example.test.ts) + onTestModuleStart (example.test.ts) + onTestSuiteReady (example.test.ts) |suite| + onTestCaseReady (example.test.ts) |skipped| + onTestCaseResult (example.test.ts) |skipped| + onTestCaseReady (example.test.ts) |running| + onTestCaseResult (example.test.ts) |running| + onTestSuiteResult (example.test.ts) |suite| + onTestModuleEnd (example.test.ts)" + `) + }) + test('dynamically skipped test case', async () => { const report = await run({ 'example.test.ts': ts` @@ -887,10 +933,10 @@ describe('merge reports', () => { onTestCaseReady (example-2.test.ts) |third| onTestCaseResult (example-2.test.ts) |third| onTestSuiteResult (example-2.test.ts) |suite| - onTestCaseReady (example-2.test.ts) |fifth| - onTestCaseResult (example-2.test.ts) |fifth| onTestCaseReady (example-2.test.ts) |fourth| onTestCaseResult (example-2.test.ts) |fourth| + onTestCaseReady (example-2.test.ts) |fifth| + onTestCaseResult (example-2.test.ts) |fifth| onTestModuleEnd (example-2.test.ts)" `) }) @@ -954,10 +1000,10 @@ describe('type checking', () => { onTestCaseReady (example-2.test-d.ts) |third| onTestCaseResult (example-2.test-d.ts) |third| onTestSuiteResult (example-2.test-d.ts) |suite| - onTestCaseReady (example-2.test-d.ts) |fifth| - onTestCaseResult (example-2.test-d.ts) |fifth| onTestCaseReady (example-2.test-d.ts) |fourth| onTestCaseResult (example-2.test-d.ts) |fourth| + onTestCaseReady (example-2.test-d.ts) |fifth| + onTestCaseResult (example-2.test-d.ts) |fifth| onTestModuleEnd (example-2.test-d.ts) onTestRunEnd (failed, 2 modules, 0 errors)"