Mocking fs module for a 3rd party library #5589
-
Hello, I'm currently trying to migrate from Jest to Vitest. With Jest, the following was working fine: But using vitest, it makes the external library that is performing a call to
I also did a reproduction repo here:
Does anyone know what I could be missing here? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
One way to extend this to external dependency is to use |
Beta Was this translation helpful? Give feedback.
vi.mock
only interceptsimport
inside the files which are processed by Vite. In your reproduction, the external dependencyto-vfile
'simport
will be kep as is, so it acceess non-mockedfs
modules.One way to extend this to external dependency is to use
server.deps.inline: ["to-vfile"]
option, which will make Vite processto-vfile
just like your source code. Here is an updated reproduction:https://stackblitz.com/edit/stackblitz-starters-rwafjx?file=vitest.config.ts