Skip to content

Mocking fs module for a 3rd party library #5589

Answered by hi-ogawa
PaulRosset asked this question in Q&A
Discussion options

You must be logged in to vote

vi.mock only intercepts import inside the files which are processed by Vite. In your reproduction, the external dependency to-vfile's import will be kep as is, so it acceess non-mocked fs modules.

One way to extend this to external dependency is to use server.deps.inline: ["to-vfile"] option, which will make Vite process to-vfile just like your source code. Here is an updated reproduction:
https://stackblitz.com/edit/stackblitz-starters-rwafjx?file=vitest.config.ts

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@PaulRosset
Comment options

@hi-ogawa
Comment options

Answer selected by PaulRosset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants