Skip to content

Commit 081cfe0

Browse files
authored
fix: correctly resolve nested mocks with index file (#6266)
1 parent c72506b commit 081cfe0

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

packages/vitest/src/runtime/mocker.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,10 @@ export class VitestMocker {
312312
return null
313313
}
314314

315-
const files = readdirSync(mockFolder)
316315
const baseOriginal = basename(path)
317316

318-
function findFile(files: string[], baseOriginal: string): string | null {
317+
function findFile(mockFolder: string, baseOriginal: string): string | null {
318+
const files = readdirSync(mockFolder)
319319
for (const file of files) {
320320
const baseFile = basename(file, extname(file))
321321
if (baseFile === baseOriginal) {
@@ -326,7 +326,7 @@ export class VitestMocker {
326326
}
327327
else {
328328
// find folder/index.{js,ts}
329-
const indexFile = findFile(readdirSync(path), 'index')
329+
const indexFile = findFile(path, 'index')
330330
if (indexFile) {
331331
return indexFile
332332
}
@@ -336,7 +336,7 @@ export class VitestMocker {
336336
return null
337337
}
338338

339-
return findFile(files, baseOriginal)
339+
return findFile(mockFolder, baseOriginal)
340340
}
341341

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy