@@ -188,7 +188,7 @@ export class VitestMocker {
188
188
return {
189
189
id,
190
190
fsPath,
191
- external,
191
+ external : external ? this . normalizePath ( external ) : external ,
192
192
}
193
193
}
194
194
@@ -315,14 +315,28 @@ export class VitestMocker {
315
315
const files = readdirSync ( mockFolder )
316
316
const baseOriginal = basename ( path )
317
317
318
- for ( const file of files ) {
319
- const baseFile = basename ( file , extname ( file ) )
320
- if ( baseFile === baseOriginal ) {
321
- return resolve ( mockFolder , file )
318
+ function findFile ( files : string [ ] , baseOriginal : string ) : string | null {
319
+ for ( const file of files ) {
320
+ const baseFile = basename ( file , extname ( file ) )
321
+ if ( baseFile === baseOriginal ) {
322
+ const path = resolve ( mockFolder , file )
323
+ // if the same name, return the file
324
+ if ( fs . statSync ( path ) . isFile ( ) ) {
325
+ return path
326
+ }
327
+ else {
328
+ // find folder/index.{js,ts}
329
+ const indexFile = findFile ( readdirSync ( path ) , 'index' )
330
+ if ( indexFile ) {
331
+ return indexFile
332
+ }
333
+ }
334
+ }
322
335
}
336
+ return null
323
337
}
324
338
325
- return null
339
+ return findFile ( files , baseOriginal )
326
340
}
327
341
328
342
const dir = dirname ( path )
@@ -517,7 +531,7 @@ export class VitestMocker {
517
531
const mocks = this . mockMap . get ( suitefile ) || { }
518
532
const resolves = this . resolveCache . get ( suitefile ) || { }
519
533
520
- mocks [ id ] = factory || this . resolveMockPath ( path , external )
534
+ mocks [ id ] = factory || this . resolveMockPath ( id , external )
521
535
resolves [ id ] = originalId
522
536
523
537
this . mockMap . set ( suitefile , mocks )
@@ -546,7 +560,7 @@ export class VitestMocker {
546
560
let mock = this . getDependencyMock ( normalizedId )
547
561
548
562
if ( mock === undefined ) {
549
- mock = this . resolveMockPath ( fsPath , external )
563
+ mock = this . resolveMockPath ( normalizedId , external )
550
564
}
551
565
552
566
if ( mock === null ) {
0 commit comments