Skip to content

Commit b166efa

Browse files
authored
fix(reporter): report tests in correct order (#7752)
1 parent b8eda4b commit b166efa

File tree

4 files changed

+54
-17
lines changed

4 files changed

+54
-17
lines changed

packages/runner/src/run.ts

+2
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ export async function runTest(test: Test, runner: VitestRunner): Promise<void> {
236236
await runner.onBeforeRunTask?.(test)
237237

238238
if (test.mode !== 'run' && test.mode !== 'queued') {
239+
updateTask('test-prepare', test, runner)
240+
updateTask('test-finished', test, runner)
239241
return
240242
}
241243

packages/vitest/src/node/test-run.ts

-11
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,6 @@ export class TestRun {
107107
// we need to report everything manually
108108
await this.reportChildren(entity.children)
109109
}
110-
else {
111-
// skipped tests need to be reported manually once test module/suite has finished
112-
for (const test of entity.children.tests('skipped')) {
113-
if (test.task.result?.pending) {
114-
// pending error tasks are reported normally
115-
continue
116-
}
117-
await this.vitest.report('onTestCaseReady', test)
118-
await this.vitest.report('onTestCaseResult', test)
119-
}
120-
}
121110

122111
if (entity.type === 'module') {
123112
await this.vitest.report('onTestModuleEnd', entity)

packages/vitest/src/utils/tasks.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export function convertTasksToEvents(file: File, onTask?: (task: Task) => void):
3737
}
3838
else {
3939
onTask?.(task)
40-
packs.push([task.id, task.result, task.meta])
41-
if (task.mode !== 'skip' && task.mode !== 'todo') {
40+
if (suite.mode !== 'skip' && suite.mode !== 'todo') {
41+
packs.push([task.id, task.result, task.meta])
4242
events.push([task.id, 'test-prepare'], [task.id, 'test-finished'])
4343
}
4444
}

test/reporters/tests/test-run.test.ts

+50-4
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,52 @@ describe('TestCase', () => {
263263
`)
264264
})
265265

266+
test('skipped test case in a different order', async () => {
267+
const report = await run({
268+
'example.test.ts': ts`
269+
test.skip('skipped', () => {});
270+
test('running', () => {});
271+
`,
272+
})
273+
274+
expect(report).toMatchInlineSnapshot(`
275+
"
276+
onTestModuleQueued (example.test.ts)
277+
onTestModuleCollected (example.test.ts)
278+
onTestModuleStart (example.test.ts)
279+
onTestCaseReady (example.test.ts) |skipped|
280+
onTestCaseResult (example.test.ts) |skipped|
281+
onTestCaseReady (example.test.ts) |running|
282+
onTestCaseResult (example.test.ts) |running|
283+
onTestModuleEnd (example.test.ts)"
284+
`)
285+
})
286+
287+
test('skipped test case in a suite with a different order', async () => {
288+
const report = await run({
289+
'example.test.ts': ts`
290+
describe('suite', () => {
291+
test.skip('skipped', () => {});
292+
test('running', () => {});
293+
})
294+
`,
295+
})
296+
297+
expect(report).toMatchInlineSnapshot(`
298+
"
299+
onTestModuleQueued (example.test.ts)
300+
onTestModuleCollected (example.test.ts)
301+
onTestModuleStart (example.test.ts)
302+
onTestSuiteReady (example.test.ts) |suite|
303+
onTestCaseReady (example.test.ts) |skipped|
304+
onTestCaseResult (example.test.ts) |skipped|
305+
onTestCaseReady (example.test.ts) |running|
306+
onTestCaseResult (example.test.ts) |running|
307+
onTestSuiteResult (example.test.ts) |suite|
308+
onTestModuleEnd (example.test.ts)"
309+
`)
310+
})
311+
266312
test('dynamically skipped test case', async () => {
267313
const report = await run({
268314
'example.test.ts': ts`
@@ -887,10 +933,10 @@ describe('merge reports', () => {
887933
onTestCaseReady (example-2.test.ts) |third|
888934
onTestCaseResult (example-2.test.ts) |third|
889935
onTestSuiteResult (example-2.test.ts) |suite|
890-
onTestCaseReady (example-2.test.ts) |fifth|
891-
onTestCaseResult (example-2.test.ts) |fifth|
892936
onTestCaseReady (example-2.test.ts) |fourth|
893937
onTestCaseResult (example-2.test.ts) |fourth|
938+
onTestCaseReady (example-2.test.ts) |fifth|
939+
onTestCaseResult (example-2.test.ts) |fifth|
894940
onTestModuleEnd (example-2.test.ts)"
895941
`)
896942
})
@@ -954,10 +1000,10 @@ describe('type checking', () => {
9541000
onTestCaseReady (example-2.test-d.ts) |third|
9551001
onTestCaseResult (example-2.test-d.ts) |third|
9561002
onTestSuiteResult (example-2.test-d.ts) |suite|
957-
onTestCaseReady (example-2.test-d.ts) |fifth|
958-
onTestCaseResult (example-2.test-d.ts) |fifth|
9591003
onTestCaseReady (example-2.test-d.ts) |fourth|
9601004
onTestCaseResult (example-2.test-d.ts) |fourth|
1005+
onTestCaseReady (example-2.test-d.ts) |fifth|
1006+
onTestCaseResult (example-2.test-d.ts) |fifth|
9611007
onTestModuleEnd (example-2.test-d.ts)
9621008
9631009
onTestRunEnd (failed, 2 modules, 0 errors)"

0 commit comments

Comments
 (0)