Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/runner/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ export async function runTest(test: Test, runner: VitestRunner): Promise<void> {
await runner.onBeforeRunTask?.(test)

if (test.mode !== 'run' && test.mode !== 'queued') {
updateTask('test-prepare', test, runner)
updateTask('test-finished', test, runner)
return
}
Comment on lines 238 to 242
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember we discussed this as early as in #7069 (comment). Happy to see it landing now! This will make resolving test state's on main thread side much easier.


Expand Down
11 changes: 0 additions & 11 deletions packages/vitest/src/node/test-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/utils/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
}
}
Expand Down
54 changes: 50 additions & 4 deletions test/reporters/tests/test-run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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)"
`)
})
Expand Down Expand Up @@ -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)"
Expand Down
Loading