Skip to content

Commit

Permalink
fix: correctly resolve nested mocks with index file (#6266)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Aug 2, 2024
1 parent c72506b commit 081cfe0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/vitest/src/runtime/mocker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,10 @@ export class VitestMocker {
return null
}

const files = readdirSync(mockFolder)
const baseOriginal = basename(path)

function findFile(files: string[], baseOriginal: string): string | null {
function findFile(mockFolder: string, baseOriginal: string): string | null {
const files = readdirSync(mockFolder)
for (const file of files) {
const baseFile = basename(file, extname(file))
if (baseFile === baseOriginal) {
Expand All @@ -326,7 +326,7 @@ export class VitestMocker {
}
else {
// find folder/index.{js,ts}
const indexFile = findFile(readdirSync(path), 'index')
const indexFile = findFile(path, 'index')
if (indexFile) {
return indexFile
}
Expand All @@ -336,7 +336,7 @@ export class VitestMocker {
return null
}

return findFile(files, baseOriginal)
return findFile(mockFolder, baseOriginal)
}

const dir = dirname(path)
Expand Down
File renamed without changes.

0 comments on commit 081cfe0

Please sign in to comment.