Skip to content

Commit

Permalink
Normalize paths in mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
illright committed Jun 17, 2024
1 parent d823688 commit ed10d9b
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions packages/steiger-plugin-fsd/src/_lib/prepare-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,19 @@ export function createFsMocks(mockedFiles: Record<string, string>, original: typ
return {
...original,
readFileSync: vi.fn(((path, options) => {
if (typeof path === 'string' && path in normalizedMockedFiles) {
return normalizedMockedFiles[path as keyof typeof normalizedMockedFiles]
const normalizedPath = typeof path === 'string' ? path.replace(/\//g, sep) : path
if (typeof normalizedPath === 'string' && normalizedPath in normalizedMockedFiles) {
return normalizedMockedFiles[normalizedPath as keyof typeof normalizedMockedFiles]
} else {
return original.readFileSync(path, options)
return original.readFileSync(normalizedPath, options)
}
}) as typeof readFileSync),
existsSync: vi.fn(((path) =>
Object.keys(normalizedMockedFiles).some(
(key) => key === path || key.startsWith(path + sep),
)) as typeof existsSync),
existsSync: vi.fn(((path) => {
const normalizedPath = typeof path === 'string' ? path.replace(/\//g, sep) : path
return Object.keys(normalizedMockedFiles).some(
(key) => key === normalizedPath || key.startsWith(normalizedPath + sep),
)
}) as typeof existsSync),
}
}

Expand Down

0 comments on commit ed10d9b

Please sign in to comment.