@@ -592,38 +592,39 @@ export class Vitest {
592592
593593 // schedule the new run
594594 this . runningPromise = ( async ( ) => {
595- if ( ! this . pool ) {
596- this . pool = createPool ( this )
597- }
595+ try {
596+ if ( ! this . pool ) {
597+ this . pool = createPool ( this )
598+ }
598599
599- const invalidates = Array . from ( this . invalidates )
600- this . invalidates . clear ( )
601- this . snapshot . clear ( )
602- this . state . clearErrors ( )
600+ const invalidates = Array . from ( this . invalidates )
601+ this . invalidates . clear ( )
602+ this . snapshot . clear ( )
603+ this . state . clearErrors ( )
603604
604- if ( ! this . isFirstRun && this . config . coverage . cleanOnRerun ) {
605- await this . coverageProvider ?. clean ( )
606- }
605+ if ( ! this . isFirstRun && this . config . coverage . cleanOnRerun ) {
606+ await this . coverageProvider ?. clean ( )
607+ }
607608
608- await this . initializeGlobalSetup ( specs )
609+ await this . initializeGlobalSetup ( specs )
609610
610- try {
611- await this . pool . runTests ( specs as WorkspaceSpec [ ] , invalidates )
612- }
613- catch ( err ) {
614- this . state . catchError ( err , 'Unhandled Error' )
615- }
611+ try {
612+ await this . pool . runTests ( specs as WorkspaceSpec [ ] , invalidates )
613+ }
614+ catch ( err ) {
615+ this . state . catchError ( err , 'Unhandled Error' )
616+ }
616617
617- const files = this . state . getFiles ( )
618+ const files = this . state . getFiles ( )
618619
619- if ( hasFailed ( files ) ) {
620- process . exitCode = 1
621- }
620+ if ( hasFailed ( files ) ) {
621+ process . exitCode = 1
622+ }
622623
623- this . cache . results . updateResults ( files )
624- await this . cache . results . writeToCache ( )
625- } ) ( )
626- . finally ( async ( ) => {
624+ this . cache . results . updateResults ( files )
625+ await this . cache . results . writeToCache ( )
626+ }
627+ finally {
627628 // can be duplicate files if different projects are using the same file
628629 const files = Array . from ( new Set ( specs . map ( spec => spec . moduleId ) ) )
629630 const errors = this . state . getUnhandledErrors ( )
@@ -632,7 +633,9 @@ export class Vitest {
632633 this . checkUnhandledErrors ( errors )
633634 await this . report ( 'onFinished' , this . state . getFiles ( files ) , errors , coverage )
634635 await this . reportCoverage ( coverage , allTestsRun )
635-
636+ }
637+ } ) ( )
638+ . finally ( ( ) => {
636639 this . runningPromise = undefined
637640 this . isFirstRun = false
638641
@@ -681,7 +684,7 @@ export class Vitest {
681684 process . exitCode = 1
682685 }
683686 } ) ( )
684- . finally ( async ( ) => {
687+ . finally ( ( ) => {
685688 this . runningPromise = undefined
686689
687690 // all subsequent runs will treat this as a fresh run
0 commit comments