Mocking cyclic dependencies with `importOriginal` doesn't work in the browser
Describe the bug
When mocking the cyclic dependency with an importOriginal/vi.importActual inside, the transformation hangs.
Reproduction
The same as:
https://github.com/vitest-dev/vitest/blob/839c39f06700144694677f94f8561f4d19a60b51/test/core/test/mocking/cyclic-import-actual.spec.ts#L5
System Info
Any
Used Package Manager
pnpm
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
Am I correct in understanding that the importOriginal module request is still mocked when it shouldn't be?
https://github.com/vitest-dev/vitest/blob/839c39f06700144694677f94f8561f4d19a60b51/test/core/test/mocking/cyclic-import-actual.spec.ts#L6
Or is the root cause elsewhere entirely?
Yes, it should return the actual module. In vite-node, we can track the call stack, but I am not sure yet if it's possible to make it work in the browser. Maybe we can inject some kind of a query to ignore in the mock handler.
Any updates on this? It would be useful to let us see an error message instead of hanging the browser.
Any updates on this? It would be useful to let us see an error message instead of hanging the browser.
Nothing new. Throwing an error would be nice, but I am not sure how to track it yet.
I'm in the process of migrating from jest to vitest and this has caused me so much headache 🤕 Glad I found this issue to at least know what is happening.
Do you think this is worthy of a FYI in the docs?
I'm in the process of migrating from jest to vitest and this has caused me so much headache 🤕 Glad I found this issue to at least know what is happening.
Do you think this is worthy of a FYI in the docs?
Yes, we can at least add it to the mocking guide. I think there are already some limitations listed.