File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -195,6 +195,30 @@ export class ViteNodeServer {
195195 return 'web'
196196 }
197197
198+ private getChangedModule (
199+ id : string ,
200+ file : string ,
201+ ) {
202+ const module = this . server . moduleGraph . getModuleById ( id ) || this . server . moduleGraph . getModuleById ( file )
203+ if ( module )
204+ return module
205+ const _modules = this . server . moduleGraph . getModulesByFile ( file )
206+ if ( ! _modules || ! _modules . size )
207+ return null
208+ // find the latest changed module
209+ const modules = [ ..._modules ]
210+ let mod = modules [ 0 ]
211+ let latestMax = - 1
212+ for ( const m of _modules ) {
213+ const timestamp = Math . max ( m . lastHMRTimestamp , m . lastInvalidationTimestamp )
214+ if ( timestamp > latestMax ) {
215+ latestMax = timestamp
216+ mod = m
217+ }
218+ }
219+ return mod
220+ }
221+
198222 private async _fetchModule ( id : string , transformMode : 'web' | 'ssr' ) : Promise < FetchResult > {
199223 let result : FetchResult
200224
@@ -212,7 +236,7 @@ export class ViteNodeServer {
212236
213237 const { path : filePath } = toFilePath ( id , this . server . config . root )
214238
215- const moduleNode = this . server . moduleGraph . getModuleById ( id ) || this . server . moduleGraph . getModuleById ( filePath )
239+ const moduleNode = this . getChangedModule ( id , filePath )
216240 const cache = this . fetchCaches [ transformMode ] . get ( filePath )
217241
218242 // lastUpdateTimestamp is the timestamp that marks the last time the module was changed
Original file line number Diff line number Diff line change @@ -705,6 +705,12 @@ export class Vitest {
705705 this . changedTests . add ( id )
706706 this . scheduleRerun ( [ id ] )
707707 }
708+ else {
709+ // it's possible that file was already there but watcher triggered "add" event instead
710+ const needsRerun = this . handleFileChanged ( id )
711+ if ( needsRerun . length )
712+ this . scheduleRerun ( needsRerun )
713+ }
708714 }
709715 const watcher = this . server . watcher
710716
You can’t perform that action at this time.
0 commit comments