@@ -188,7 +188,7 @@ export class VitestMocker {
188188 return {
189189 id,
190190 fsPath,
191- external,
191+ external : external ? this . normalizePath ( external ) : external ,
192192 }
193193 }
194194
@@ -315,14 +315,28 @@ export class VitestMocker {
315315 const files = readdirSync ( mockFolder )
316316 const baseOriginal = basename ( path )
317317
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+ }
322335 }
336+ return null
323337 }
324338
325- return null
339+ return findFile ( files , baseOriginal )
326340 }
327341
328342 const dir = dirname ( path )
@@ -517,7 +531,7 @@ export class VitestMocker {
517531 const mocks = this . mockMap . get ( suitefile ) || { }
518532 const resolves = this . resolveCache . get ( suitefile ) || { }
519533
520- mocks [ id ] = factory || this . resolveMockPath ( path , external )
534+ mocks [ id ] = factory || this . resolveMockPath ( id , external )
521535 resolves [ id ] = originalId
522536
523537 this . mockMap . set ( suitefile , mocks )
@@ -546,7 +560,7 @@ export class VitestMocker {
546560 let mock = this . getDependencyMock ( normalizedId )
547561
548562 if ( mock === undefined ) {
549- mock = this . resolveMockPath ( fsPath , external )
563+ mock = this . resolveMockPath ( normalizedId , external )
550564 }
551565
552566 if ( mock === null ) {
0 commit comments