@@ -129,12 +129,20 @@ export async function startVitest(
129129 stdinCleanup = registerConsoleShortcuts ( ctx , stdin , stdout )
130130 }
131131
132- ctx . onAfterSetServer ( ( ) => {
133- if ( ctx . config . standalone ) {
134- ctx . standalone ( )
132+ ctx . onAfterSetServer ( async ( ) => {
133+ if ( ctx . closingPromise ) {
134+ return
135135 }
136- else {
137- ctx . start ( cliFilters )
136+ try {
137+ if ( ctx . config . standalone ) {
138+ await ctx . standalone ( )
139+ }
140+ else {
141+ await ctx . start ( cliFilters )
142+ }
143+ }
144+ catch ( error ) {
145+ reportStartError ( ctx , error )
138146 }
139147 } )
140148
@@ -157,27 +165,7 @@ export async function startVitest(
157165 return ctx
158166 }
159167 catch ( e ) {
160- if ( e instanceof FilesNotFoundError ) {
161- return ctx
162- }
163-
164- if ( e instanceof GitNotFoundError ) {
165- ctx . logger . error ( e . message )
166- return ctx
167- }
168-
169- if (
170- e instanceof IncludeTaskLocationDisabledError
171- || e instanceof RangeLocationFilterProvidedError
172- || e instanceof LocationFilterFileNotFoundError
173- ) {
174- ctx . logger . printError ( e , { verbose : false } )
175- return ctx
176- }
177-
178- process . exitCode = 1
179- ctx . logger . printError ( e , { fullStack : true , type : 'Unhandled Error' } )
180- ctx . logger . error ( '\n\n' )
168+ reportStartError ( ctx , e )
181169 return ctx
182170 }
183171 finally {
@@ -188,6 +176,30 @@ export async function startVitest(
188176 }
189177}
190178
179+ function reportStartError ( ctx : Vitest , error : unknown ) : void {
180+ if ( error instanceof FilesNotFoundError ) {
181+ return
182+ }
183+
184+ if ( error instanceof GitNotFoundError ) {
185+ ctx . logger . error ( error . message )
186+ return
187+ }
188+
189+ if (
190+ error instanceof IncludeTaskLocationDisabledError
191+ || error instanceof RangeLocationFilterProvidedError
192+ || error instanceof LocationFilterFileNotFoundError
193+ ) {
194+ ctx . logger . printError ( error , { verbose : false } )
195+ return
196+ }
197+
198+ process . exitCode = 1
199+ ctx . logger . printError ( error , { fullStack : true , type : 'Unhandled Error' } )
200+ ctx . logger . error ( '\n\n' )
201+ }
202+
191203export async function prepareVitest (
192204 options ?: CliOptions ,
193205 viteOverrides ?: ViteUserConfig ,
0 commit comments