@@ -592,38 +592,39 @@ export class Vitest {
592
592
593
593
// schedule the new run
594
594
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
+ }
598
599
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 ( )
603
604
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
+ }
607
608
608
- await this . initializeGlobalSetup ( specs )
609
+ await this . initializeGlobalSetup ( specs )
609
610
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
+ }
616
617
617
- const files = this . state . getFiles ( )
618
+ const files = this . state . getFiles ( )
618
619
619
- if ( hasFailed ( files ) ) {
620
- process . exitCode = 1
621
- }
620
+ if ( hasFailed ( files ) ) {
621
+ process . exitCode = 1
622
+ }
622
623
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 {
627
628
// can be duplicate files if different projects are using the same file
628
629
const files = Array . from ( new Set ( specs . map ( spec => spec . moduleId ) ) )
629
630
const errors = this . state . getUnhandledErrors ( )
@@ -632,7 +633,9 @@ export class Vitest {
632
633
this . checkUnhandledErrors ( errors )
633
634
await this . report ( 'onFinished' , this . state . getFiles ( files ) , errors , coverage )
634
635
await this . reportCoverage ( coverage , allTestsRun )
635
-
636
+ }
637
+ } ) ( )
638
+ . finally ( ( ) => {
636
639
this . runningPromise = undefined
637
640
this . isFirstRun = false
638
641
@@ -681,7 +684,7 @@ export class Vitest {
681
684
process . exitCode = 1
682
685
}
683
686
} ) ( )
684
- . finally ( async ( ) => {
687
+ . finally ( ( ) => {
685
688
this . runningPromise = undefined
686
689
687
690
// all subsequent runs will treat this as a fresh run
0 commit comments