> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# federation


[Added in v0.11.10](https://github.com/web-infra-dev/rstest/releases/tag/v0.11.10)

- **Type:** `boolean`
- **Default:** `false`
- **CLI:** `--federation`

Whether to enable [Module Federation](https://module-federation.io/) support.

Rstest supports Module Federation in both Node Mode (including DOM-simulated environments such as `jsdom`) and Browser Mode.

When enabled, Rstest installs runtime shims in the test worker so that a Module Federation runtime can load remote entries and chunks through Rstest's module loader while module mocks stay effective.


**CLI**

```bash
npx rstest --federation
```


**rstest.config.ts**

```ts
import { defineConfig } from '@rstest/core';

export default defineConfig({
  federation: true,
});
```


## Testing a federated app

`federation` only turns on Rstest's test runtime support; it does not configure remotes, exposes, or shared modules. When you use [@module-federation/rstest](https://github.com/module-federation/core), the plugin configures the Module Federation build and automatically enables Rstest's compatibility mode for Node-based test environments, so you do not need to set `federation: true` again there.

In Browser Mode the plugin does not turn on the `federation` option. However, `globalSetup` files always run in a Node process, and their build output carries the same federation runtime, which throws on load without the switch. Set `federation: true` yourself whenever a Browser Mode project uses `globalSetup`.

Start with the [Module Federation guide](/guide/advanced/module-federation.md) for installation and the Rstest testing workflow. See the [official Rstest integration guide](https://module-federation.io/integrations/build-tool/rstest.html) for reusing an Rsbuild federation configuration and the complete plugin options.

```ts title="rstest.config.ts"
import { federation } from '@module-federation/rstest';
import { defineConfig } from '@rstest/core';

export default defineConfig({
  plugins: [
    federation({
      name: 'main_app',
      remotes: {
        'component-app': 'component_app@http://localhost:3001/remoteEntry.cjs',
      },
      shared: {
        react: { singleton: true },
      },
    }),
  ],
});
```

This Node-based example consumes a Node-targeted `remoteEntry.cjs`. Browser Mode should consume the browser build's `remoteEntry.js`. See the [Module Federation guide](/guide/advanced/module-federation.md) for the distinction and the [Node](https://github.com/rstackjs/rstack-examples/tree/main/rstest/module-federation-node) and [Browser](https://github.com/rstackjs/rstack-examples/tree/main/rstest/module-federation-browser) examples for complete setups.
