Skip to content

Commit

Permalink
fix: checking for mock inside nested dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Dec 28, 2021
1 parent 7442a59 commit 0816091
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/vitest/src/node/mocker.ts
Expand Up @@ -13,15 +13,17 @@ function resolveMockPath(mockPath: string, root: string, nmName: string | null)
// it's a node_module alias
// all mocks should be inside <root>/__mocks__
if (nmName) {
const mockFolder = resolve(root, '__mocks__')
const mockDirname = dirname(nmName) // for nested mocks: @vueuse/integration/useJwt
const baseFilename = basename(nmName)
const mockFolder = resolve(root, '__mocks__', mockDirname)

if (!existsSync(mockFolder)) return null

const files = readdirSync(mockFolder)

for (const file of files) {
const [basename] = file.split('.')
if (basename === nmName)
if (basename === baseFilename)
return resolve(mockFolder, file).replace(root, '')
}

Expand Down

0 comments on commit 0816091

Please sign in to comment.