@@ -5,7 +5,6 @@ import { basename, dirname, join, normalize, relative, resolve } from 'pathe'
5
5
import fg from 'fast-glob'
6
6
import mm from 'micromatch'
7
7
import c from 'picocolors'
8
- import { normalizeRequestId } from 'vite-node/utils'
9
8
import { ViteNodeRunner } from 'vite-node/client'
10
9
import { SnapshotManager } from '@vitest/snapshot/manager'
11
10
import type { CancelReason , File } from '@vitest/runner'
@@ -646,23 +645,23 @@ export class Vitest {
646
645
} , WATCHER_DEBOUNCE )
647
646
}
648
647
649
- public getModuleProjects ( id : string ) {
648
+ public getModuleProjects ( filepath : string ) {
650
649
return this . projects . filter ( ( project ) => {
651
- return project . getModulesByFilepath ( id ) . size
650
+ return project . getModulesByFilepath ( filepath ) . size
652
651
// TODO: reevaluate || project.browser?.moduleGraph.getModulesByFile(id)?.size
653
652
} )
654
653
}
655
654
656
655
private unregisterWatcher = noop
657
656
private registerWatcher ( ) {
658
- const updateLastChanged = ( id : string ) => {
659
- const projects = this . getModuleProjects ( id )
657
+ const updateLastChanged = ( filepath : string ) => {
658
+ const projects = this . getModuleProjects ( filepath )
660
659
projects . forEach ( ( { server, browser } ) => {
661
- const serverMods = server . moduleGraph . getModulesByFile ( id )
660
+ const serverMods = server . moduleGraph . getModulesByFile ( filepath )
662
661
serverMods ?. forEach ( mod => server . moduleGraph . invalidateModule ( mod ) )
663
662
664
663
if ( browser ) {
665
- const browserMods = browser . moduleGraph . getModulesByFile ( id )
664
+ const browserMods = browser . moduleGraph . getModulesByFile ( filepath )
666
665
browserMods ?. forEach ( mod => browser . moduleGraph . invalidateModule ( mod ) )
667
666
}
668
667
} )
@@ -725,62 +724,56 @@ export class Vitest {
725
724
/**
726
725
* @returns A value indicating whether rerun is needed (changedTests was mutated)
727
726
*/
728
- private handleFileChanged ( id : string ) : string [ ] {
729
- if ( this . changedTests . has ( id ) || this . invalidates . has ( id ) )
727
+ private handleFileChanged ( filepath : string ) : string [ ] {
728
+ if ( this . changedTests . has ( filepath ) || this . invalidates . has ( filepath ) )
730
729
return [ ]
731
730
732
- if ( mm . isMatch ( id , this . config . forceRerunTriggers ) ) {
731
+ if ( mm . isMatch ( filepath , this . config . forceRerunTriggers ) ) {
733
732
this . state . getFilepaths ( ) . forEach ( file => this . changedTests . add ( file ) )
734
- return [ id ]
733
+ return [ filepath ]
735
734
}
736
735
737
- const projects = this . getModuleProjects ( id )
736
+ const projects = this . getModuleProjects ( filepath )
738
737
if ( ! projects . length ) {
739
738
// if there are no modules it's possible that server was restarted
740
739
// we don't have information about importers anymore, so let's check if the file is a test file at least
741
- if ( this . state . filesMap . has ( id ) || this . projects . some ( project => project . isTestFile ( id ) ) ) {
742
- this . changedTests . add ( id )
743
- return [ id ]
740
+ if ( this . state . filesMap . has ( filepath ) || this . projects . some ( project => project . isTestFile ( filepath ) ) ) {
741
+ this . changedTests . add ( filepath )
742
+ return [ filepath ]
744
743
}
745
744
return [ ]
746
745
}
747
746
748
747
const files : string [ ] = [ ]
749
748
750
749
for ( const project of projects ) {
751
- const { server } = project
752
- const mods = project . getModulesByFilepath ( id )
750
+ const mods = project . getModulesByFilepath ( filepath )
753
751
if ( ! mods . size )
754
752
continue
755
753
756
- // remove queries from id
757
- id = normalizeRequestId ( id , server . config . base )
758
-
759
- this . invalidates . add ( id )
754
+ this . invalidates . add ( filepath )
760
755
761
756
// one of test files that we already run, or one of test files that we can run
762
- if ( this . state . filesMap . has ( id ) || project . isTestFile ( id ) ) {
763
- this . changedTests . add ( id )
764
- files . push ( id )
757
+ if ( this . state . filesMap . has ( filepath ) || project . isTestFile ( filepath ) ) {
758
+ this . changedTests . add ( filepath )
759
+ files . push ( filepath )
765
760
continue
766
761
}
767
762
768
763
let rerun = false
769
764
for ( const mod of mods ) {
770
- if ( ! mod . id )
771
- continue
772
765
mod . importers . forEach ( ( i ) => {
773
- if ( ! i . id )
766
+ if ( ! i . file )
774
767
return
775
768
776
- const heedsRerun = this . handleFileChanged ( i . id )
769
+ const heedsRerun = this . handleFileChanged ( i . file )
777
770
if ( heedsRerun )
778
771
rerun = true
779
772
} )
780
773
}
781
774
782
775
if ( rerun )
783
- files . push ( id )
776
+ files . push ( filepath )
784
777
}
785
778
786
779
return files
0 commit comments