@@ -703,14 +703,15 @@ export class Vitest {
703703
704704 async close ( ) {
705705 if ( ! this . closingPromise ) {
706- const closePromises = this . projects . map ( w => w . close ( ) )
706+ const closePromises = this . projects . map ( w => w . close ( ) . then ( ( ) => w . server = undefined as any ) )
707707 // close the core workspace server only once
708708 if ( this . coreWorkspace && ! this . projects . includes ( this . coreWorkspace ) )
709- closePromises . push ( this . server . close ( ) )
710- this . closingPromise = Promise . allSettled ( [
711- this . pool ?. close ( ) ,
712- ...closePromises ,
713- ] . filter ( Boolean ) ) . then ( ( results ) => {
709+ closePromises . push ( this . server . close ( ) . then ( ( ) => this . server = undefined as any ) )
710+
711+ if ( this . pool )
712+ closePromises . push ( this . pool . close ( ) . then ( ( ) => this . pool = undefined ) )
713+
714+ this . closingPromise = Promise . allSettled ( closePromises ) . then ( ( results ) => {
714715 results . filter ( r => r . status === 'rejected' ) . forEach ( ( err ) => {
715716 this . logger . error ( 'error during close' , ( err as PromiseRejectedResult ) . reason )
716717 } )
@@ -727,6 +728,20 @@ export class Vitest {
727728 this . report ( 'onProcessTimeout' ) . then ( ( ) => {
728729 console . warn ( `close timed out after ${ this . config . teardownTimeout } ms` )
729730 this . state . getProcessTimeoutCauses ( ) . forEach ( cause => console . warn ( cause ) )
731+
732+ if ( ! this . pool ) {
733+ const runningServers = [ this . server , ...this . projects . map ( p => p . server ) ] . filter ( Boolean ) . length
734+
735+ if ( runningServers === 1 )
736+ console . warn ( 'Tests closed successfully but something prevents Vite server from exiting' )
737+ else if ( runningServers > 1 )
738+ console . warn ( `Tests closed successfully but something prevents ${ runningServers } Vite servers from exiting` )
739+ else
740+ console . warn ( 'Tests closed successfully but something prevents the main process from exiting' )
741+
742+ console . warn ( 'You can try to identify the cause by enabling "hanging-process" reporter. See https://vitest.dev/config/#reporters' )
743+ }
744+
730745 process . exit ( )
731746 } )
732747 } , this . config . teardownTimeout ) . unref ( )
0 commit comments