plugins
plugins
plugins is used to register Rsbuild plugins.
Rstest and Rsbuild share the same plugin system, so you can use Rsbuild plugins in Rstest.
Using plugins
You can register Rsbuild plugins in rstest.config.* using the plugins option, see Rsbuild - plugins.
Discover plugins
Check out the Rsbuild plugin list to discover available plugins. These plugins can also be used with Rstest.
Modify Rstest config in Rsbuild plugins
When an Rsbuild plugin runs inside Rstest, it can get the Rstest exposed API through api.useExposed from the Rsbuild Plugin API and call modifyRstestConfig to adjust the Rstest config for the current project.
This API is currently exposed only for Node-mode projects. Browser Mode projects do not receive the rstest exposed API, so api.useExposed('rstest') returns undefined there.
This API is intended for framework integrations and toolchain plugins. When a plugin already knows the current framework, Rsbuild environment, or project conventions, it can centrally add project config such as test entries, exclude rules, setup files, aliases, defines, or testEnvironment so users do not need to duplicate the same information in their Rstest config.
In multi-project mode, Rstest exposes one API for each Rsbuild environment. A plugin registered in one project only modifies that project's Rstest config and does not affect other projects.
Type definitions
RstestExposeAPI is exported from @rstest/core and is the type of the API exposed by Rstest to Rsbuild plugins through api.useExposed('rstest').
RstestConfig is the same user-facing config shape accepted by defineConfig. You can either mutate the received config object directly or return a config fragment that matches the RstestConfig shape. Rstest merges, normalizes, and validates these changes again after the callback finishes. The callback can also be asynchronous.
Register modifyRstestConfig during the Rsbuild plugin setup phase. Do not register it from later Rsbuild config hooks such as api.modifyRsbuildConfig, because Rstest applies collected callbacks while resolving the Rsbuild config; callbacks registered inside those hooks are too late for the current resolution pass.
Modifiable config fields
modifyRstestConfig only adjusts the current project's config. If a callback modifies an unsupported field, Rstest throws an error that tells you to configure it in rstest.config.* instead.
If you need to add Rsbuild plugins dynamically, integrate through Rstest's extends adapter pattern instead. An adapter can prepare the Rstest config before Rsbuild plugin initialization starts.