Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to run tests with remote modules #5572

Closed
6 tasks done
testrobpoc opened this issue Apr 19, 2024 · 2 comments
Closed
6 tasks done

Fails to run tests with remote modules #5572

testrobpoc opened this issue Apr 19, 2024 · 2 comments

Comments

@testrobpoc
Copy link

testrobpoc commented Apr 19, 2024

Describe the bug

Hey guys, I have a problem to run tests using Vitest, when we have Imports for remote modules (Webpack based module federations). its raising this error:
Screenshot 2024-04-19 at 11 36 00

I tried to mock it as virtual module by adding this:
alias: { '$remote/App': path.resolve('./__mocks__/test.ts') }

But still no luck.

NOTE: we are using Vitest on webpack based app. Because module federation is needed for us, and we can't use Vite with it's https://github.com/originjs/vite-plugin-federation plugin because it has a big issues in here: originjs/vite-plugin-federation#294 which makes the whole plugin useless.

Reproduction

https://stackblitz.com/edit/vitejs-vite-pq9gts?file=vitest.config.ts,src%2Fapp%2FApp.tsx,src%2Fapp%2FApp.test.tsx&terminal=dev

System Info

"@vitest/ui": "1.4.0",
"vitest": "1.4.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"

Node version: v20.11.1

Used Package Manager

pnpm

Validations

@hi-ogawa
Copy link
Contributor

Is it intended you have $remote/App instead remote/App? I'm not sure about the broader context with module federation, but if it's just typo, then remote/App alias is working for me:
https://stackblitz.com/edit/vitejs-vite-rtlmzb?file=vitest.config.ts

@testrobpoc
Copy link
Author

Is it intended you have $remote/App instead remote/App? I'm not sure about the broader context with module federation, but if it's just typo, then remote/App alias is working for me: https://stackblitz.com/edit/vitejs-vite-rtlmzb?file=vitest.config.ts

Thanks! That dollar sign from Vitest documentation https://vitest.dev/guide/mocking.html#virtual-modules tricked me up! All works now!

@github-actions github-actions bot locked and limited conversation to collaborators May 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants