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 federated module #5684

Open
6 tasks done
adarshdeep-ld opened this issue May 7, 2024 · 1 comment
Open
6 tasks done

Fails to run tests with federated module #5684

adarshdeep-ld opened this issue May 7, 2024 · 1 comment

Comments

@adarshdeep-ld
Copy link

adarshdeep-ld commented May 7, 2024

Describe the bug

Hey folks, I found a problem that I don't know how to solve. I'm using module federation (@originjs/vite-plugin-federation) to get a remote module and since I've added config my tests are failing,

Here is my config:

export default defineConfig(() => ({
  plugins: [
    ElementPlus(),
    vue(),
    federation({
      name: 'team-red',
      remotes: {
        "team-blue": "http://localhost:5002/assets/remoteEntry.js",
        "team-green": "http://localhost:5001/assets/remoteEntry.js",
      },
      shared: ['vue','pinia']
  })
  ],
  build:{
    minify: false,
    target: ["chrome89", "edge89", "firefox89", "safari15"],
  },
  test: {
    globals: true,
    environment: "happy-dom",
    include: ["./src/**/*.{test,spec}.?(c|m)[jt]s?(x)"], 
  },
}))

I have just tried to mount the component that uses remote components and it gives the following error:
image

So is there any way to work around it and get my test working?

Reproduction

I have reproduced the error on an example given be vite-plugin-federation
https://github.com/adarshdeep-ld/vite-plugin-federation
You can clone the above repository and follow steps mention in the following Readme
https://github.com/adarshdeep-ld/vite-plugin-federation/blob/main/packages/examples/vue3-advanced-demo/README.md

System Info

Node Version: v20.11.1
pnpm Version: v9.1.0

Used Package Manager

pnpm

Validations

@hi-ogawa
Copy link
Contributor

hi-ogawa commented May 8, 2024

Not familiar with module federation ideas, but I'm guessing the whole point of module federation is to not have to unit test entire modules.

If that's the case, they might simply recommend skipping their plugin during unit test by:

plugins: [
  ...,
  !process.env.VITEST && federation({ ... }),
]

Probably, it's better to ask on their end about what's the recommendation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants