[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

fix: correctly resolve nested mocks with `index` file (#6266)

authored by

Vladimir and committed by
GitHub
(Aug 2, 2024, 11:10 AM +0200) 081cfe03 c72506b1

+9 -9
-5
test/core/__mocks__/axios.ts
··· 1 - import { vi } from 'vitest' 2 - 3 - export default { 4 - get: vi.fn(), 5 - }
+4 -4
packages/vitest/src/runtime/mocker.ts
··· 312 312 return null 313 313 } 314 314 315 - const files = readdirSync(mockFolder) 316 315 const baseOriginal = basename(path) 317 316 318 - function findFile(files: string[], baseOriginal: string): string | null { 317 + function findFile(mockFolder: string, baseOriginal: string): string | null { 318 + const files = readdirSync(mockFolder) 319 319 for (const file of files) { 320 320 const baseFile = basename(file, extname(file)) 321 321 if (baseFile === baseOriginal) { ··· 326 326 } 327 327 else { 328 328 // find folder/index.{js,ts} 329 - const indexFile = findFile(readdirSync(path), 'index') 329 + const indexFile = findFile(path, 'index') 330 330 if (indexFile) { 331 331 return indexFile 332 332 } ··· 336 336 return null 337 337 } 338 338 339 - return findFile(files, baseOriginal) 339 + return findFile(mockFolder, baseOriginal) 340 340 } 341 341 342 342 const dir = dirname(path)
+5
test/core/__mocks__/axios/index.ts
··· 1 + import { vi } from 'vitest' 2 + 3 + export default { 4 + get: vi.fn(), 5 + }