File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff 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+
2035it ( '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 } )
You can’t perform that action at this time.
0 commit comments