@@ -377,11 +377,9 @@ export class Vitest {
377
377
// populate once, update cache on watch
378
378
await this . cache . stats . populateStats ( this . config . root , files )
379
379
380
- await this . runFiles ( files )
380
+ await this . runFiles ( files , true )
381
381
}
382
382
383
- await this . reportCoverage ( true )
384
-
385
383
if ( this . config . watch )
386
384
await this . report ( 'onWatcherStart' )
387
385
}
@@ -472,7 +470,7 @@ export class Vitest {
472
470
await project . initializeGlobalSetup ( )
473
471
}
474
472
475
- async runFiles ( paths : WorkspaceSpec [ ] ) {
473
+ async runFiles ( paths : WorkspaceSpec [ ] , allTestsRun : boolean ) {
476
474
const filepaths = paths . map ( ( [ , file ] ) => file )
477
475
this . state . collectPaths ( filepaths )
478
476
@@ -492,6 +490,10 @@ export class Vitest {
492
490
this . invalidates . clear ( )
493
491
this . snapshot . clear ( )
494
492
this . state . clearErrors ( )
493
+
494
+ if ( ! this . isFirstRun && this . config . coverage . cleanOnRerun )
495
+ await this . coverageProvider ?. clean ( )
496
+
495
497
await this . initializeGlobalSetup ( paths )
496
498
497
499
try {
@@ -513,7 +515,10 @@ export class Vitest {
513
515
// can be duplicate files if different projects are using the same file
514
516
const specs = Array . from ( new Set ( paths . map ( ( [ , p ] ) => p ) ) )
515
517
await this . report ( 'onFinished' , this . state . getFiles ( specs ) , this . state . getUnhandledErrors ( ) )
518
+ await this . reportCoverage ( allTestsRun )
519
+
516
520
this . runningPromise = undefined
521
+ this . isFirstRun = false
517
522
} )
518
523
519
524
return await this . runningPromise
@@ -530,13 +535,8 @@ export class Vitest {
530
535
files = files . filter ( file => filteredFiles . some ( f => f [ 1 ] === file ) )
531
536
}
532
537
533
- if ( this . coverageProvider && this . config . coverage . cleanOnRerun )
534
- await this . coverageProvider . clean ( )
535
-
536
538
await this . report ( 'onWatcherRerun' , files , trigger )
537
- await this . runFiles ( files . flatMap ( file => this . getProjectsByTestFile ( file ) ) )
538
-
539
- await this . reportCoverage ( ! trigger )
539
+ await this . runFiles ( files . flatMap ( file => this . getProjectsByTestFile ( file ) ) , ! trigger )
540
540
541
541
await this . report ( 'onWatcherStart' , this . state . getFiles ( files ) )
542
542
}
@@ -632,16 +632,11 @@ export class Vitest {
632
632
633
633
this . changedTests . clear ( )
634
634
635
- if ( this . coverageProvider && this . config . coverage . cleanOnRerun )
636
- await this . coverageProvider . clean ( )
637
-
638
635
const triggerIds = new Set ( triggerId . map ( id => relative ( this . config . root , id ) ) )
639
636
const triggerLabel = Array . from ( triggerIds ) . join ( ', ' )
640
637
await this . report ( 'onWatcherRerun' , files , triggerLabel )
641
638
642
- await this . runFiles ( files . flatMap ( file => this . getProjectsByTestFile ( file ) ) )
643
-
644
- await this . reportCoverage ( false )
639
+ await this . runFiles ( files . flatMap ( file => this . getProjectsByTestFile ( file ) ) , false )
645
640
646
641
await this . report ( 'onWatcherStart' , this . state . getFiles ( files ) )
647
642
} , WATCHER_DEBOUNCE )
0 commit comments