When you use the CLI of Rstest, Rstest will automatically read the configuration file in the root directory of the current project and resolve it in the following order:
rstest.config.mjs
rstest.config.ts
rstest.config.js
rstest.config.cjs
rstest.config.mts
rstest.config.cts
We recommend using the .mjs
or .ts
format for the configuration file and importing the defineConfig
utility function from @rstest/core
. It provides friendly TypeScript type hints and autocompletion, which can help you avoid errors in the configuration.
If you are developing a non-TypeScript project, you can use the .mjs
format for the configuration file.
Rstest CLI uses the --config
option to specify the config file, which can be set to a relative path or an absolute path.
You can also abbreviate the --config
option to -c
:
Rstest's build configuration inherits from Rsbuild. Therefore, in Rstest, you can use most of the Rsbuild configurations, such as:
More configurations can be referred to Build Configurations.
Rstest uses Rspack for building, so you can directly use Rspack's configuration options to configure Rstest's build behavior.
More details can be referred to Configure Rspack.
You can use process.env.RSTEST
to detect whether it is an Rstest test environment to apply different configurations/codes in your tests.
It should be noted that if you use process.env.RSTEST
in your source code, define process.env.RSTEST
as false
in your build configuration (such as rsbuild.config.ts
) during production builds, this will help the bundler eliminate dead code.
If you are developing the Rsbuild plugin, you can use api.context.callerName to determine the current plugin is being called.