federation
- Type:
boolean - Default:
false - CLI:
--federation
Whether to enable Module Federation compatibility mode.
This option applies to Rstest's Node-based runner, including testEnvironment: 'node' and DOM-simulated environments such as jsdom and happy-dom. It does not enable or change Rstest Browser Mode (browser.enabled: true).
Rstest evaluates test bundles inside a single worker runtime so that module mocks stay effective. Module Federation runtimes load remote entries and chunks on their own — via Node fs/vm/eval or over HTTP — outside of that runtime. When federation is enabled, Rstest installs additional runtime shims to make the two work together:
- Externalized dynamic imports get a
globalThisfallback, so federation runtime chunks evaluated viavm/evalcan still load modules with Node's native dynamic import. - Module Federation's placeholder chunk handlers (
consumes/remotes) are kept from throwing before the federation runtime initializes. - Federation runtime plugins cannot replace Rstest's chunk-loading handlers, which would otherwise evaluate chunks outside the test runtime and lose mocks.
Testing a federated app
federation only prepares the test runtime. The Module Federation build itself (remotes, exposes, shared modules) is configured through a bundler plugin such as @module-federation/rstest, which applies the federation setup to the Rstest build:
See the federation example for a complete setup with HTTP remotes, local CommonJS remotes, and SSR tests.