File tree 2 files changed +31
-1
lines changed
2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -195,6 +195,30 @@ export class ViteNodeServer {
195
195
return 'web'
196
196
}
197
197
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
+
198
222
private async _fetchModule ( id : string , transformMode : 'web' | 'ssr' ) : Promise < FetchResult > {
199
223
let result : FetchResult
200
224
@@ -212,7 +236,7 @@ export class ViteNodeServer {
212
236
213
237
const { path : filePath } = toFilePath ( id , this . server . config . root )
214
238
215
- const moduleNode = this . server . moduleGraph . getModuleById ( id ) || this . server . moduleGraph . getModuleById ( filePath )
239
+ const moduleNode = this . getChangedModule ( id , filePath )
216
240
const cache = this . fetchCaches [ transformMode ] . get ( filePath )
217
241
218
242
// 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 {
705
705
this . changedTests . add ( id )
706
706
this . scheduleRerun ( [ id ] )
707
707
}
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
+ }
708
714
}
709
715
const watcher = this . server . watcher
710
716
You can’t perform that action at this time.
0 commit comments