Skip to content

Commit b7572c1

Browse files
jszumskiclaude
andauthored
fix: report global setup errors instead of "no test files" (#12031)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 68dc42c commit b7572c1

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎packages/vitest/src/node/core.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,17 @@ export class Vitest {
10761076
await this.coverageProvider?.clean()
10771077
}
10781078

1079-
await this.initializeGlobalSetup(specs)
1079+
try {
1080+
await this.initializeGlobalSetup(specs)
1081+
} catch (err) {
1082+
// record the error before `finally` ends the run, otherwise
1083+
// reporters see no modules and print "No test files found"
1084+
this.state.catchError(err, 'Unhandled Error')
1085+
return {
1086+
testModules: [],
1087+
unhandledErrors: this.state.getUnhandledErrors(),
1088+
}
1089+
}
10801090

10811091
try {
10821092
const sorted = await this.getSequencer().sort(specs)

‎test/e2e/test/global-setup.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ it('should fail', async () => {
1717
expect(stderr).toContain('globalSetup/error.ts:6:9')
1818
})
1919

20+
it('reports the global setup error instead of "No test files found"', async () => {
21+
const root = resolve(import.meta.dirname, '../fixtures/global-setup-fail')
22+
const { stdout, exitCode, errorTree } = await runVitest({ root })
23+
24+
expect(exitCode).toBe(1)
25+
expect(stdout).not.toContain('No test files found')
26+
expect(errorTree()).toMatchInlineSnapshot(`
27+
{
28+
"__unhandled_errors__": [
29+
"error",
30+
],
31+
}
32+
`)
33+
})
34+
2035
it('fails with a non-zero exit code when teardown throws', async () => {
2136
const root = resolve(import.meta.dirname, '../fixtures/global-setup-teardown-fail')
2237
const { stderr, exitCode } = await runVitest({ root })

0 commit comments

Comments
 (0)