Closed eironman closed 3 years ago
Hi,
I'm not sure if a unit test is the right tool for testing module federation. IMHO, it's more of an e2e or integration test thing.
However, in general, you can avoid this error by importing the used code via a dynamic import. This is where module federation hooks in to load the remotes.
I've been having a similar issue. I installed the plugin into an Angular app, and the existing unit tests started failing with a similar message. (I'm not trying to test module federation -- these are tests of existing functionality that used to pass before installing the plugin.)
For the time being, I'm following the guidance here to work around this issue -- essentially, setting each shared dependency to 'eager: true'. But is there a better way?
What extra configuration will allow Karma/Jasmine tests to pass? (What would the guidance in your previous comment look like?)
I couldn't solve it, I had to move from Karma/Jasmine to Jest, but that was with Angular 11, maybe with Angular 12 it works.
I couldn't solve it, I had to move from Karma/Jasmine to Jest, but that was with Angular 11, maybe with Angular 12 it works.
Bad news. It doesn't. I just converted my existing small angular12 app to module federation and my tests stopped working.
@manfredsteyer the purpose of our unit tests is to test individual components and services, not to test the module federation.
You can remove extraWebpackConfig
in angular.json for test configuration part or provide specific webpack config without shared libs
I am trying to run tests with Karma for Angular 11 and Webpack5, but I get this error for both the shell and the federated app:
Uncaught Error: Shared module is not available for eager consumption
I've found this article which writes about this issue, but I still can't make it work.
https://medium.com/dev-genius/module-federation-advanced-api-inwebpack-5-0-0-beta-17-71cd4d42e534