Rstest supports running multiple test projects simultaneously within a single Rstest process. These projects can have different test configurations and test environments.
Define each sub-project in a monorepo as a project through the projects field, where each sub-project has its own test configuration.
Rstest will automatically recognize each subdirectory under the packages directory as an independent test project and run tests according to the rstest.config.ts file (if present) in the subdirectory.
import { defineConfig } from '@rstest/core';
export default defineConfig({
projects: [
// A monorepo: each package directory is a project
'packages/*',
],
});You can define multiple test projects through the projects field. Rstest will run the corresponding tests according to the configurations defined by each project, and all test results will be merged and displayed.
If there is no projects field, rstest will treat the current directory as a single project.
The projects field supports the following configuration methods:
projects field. This allows you to define multiple test projects within a single project without creating separate configuration files for each test project.import { defineConfig } from '@rstest/core';
export default defineConfig({
projects: [
// A monorepo: each package directory is a project
'packages/*',
// All projects under the apps directory that provide an rstest config file
'apps/**/rstest.config.ts',
// A specific project directory
'<rootDir>/services/auth',
// A specific project's config file
'./projects/web/rstest.config.ts',
// inline project configs
{
name: 'node',
include: ['tests/node/**/*.{test,spec}.{js,cjs,mjs,ts,tsx}'],
},
{
name: 'react',
include: ['tests/react/**/*.{test,spec}.{js,cjs,mjs,ts,tsx}'],
testEnvironment: 'jsdom',
},
],
});When the projects field exists in the root directory's rstest config file, Rstest will not treat it as a test project. In this case, the root directory's rstest.config file is only used to define projects and global configuration.
If you want to treat the root directory as a project as well, you can define the test configuration for the root directory in projects.
import { defineConfig } from '@rstest/core';
export default defineConfig({
projects: [
{
name: 'root',
include: ['<rootDir>/tests/**/*.{test,spec}.{js,cjs,mjs,ts,tsx}'],
},
'packages/*',
],
});The following configurations are global configurations and are invalid when configured in projects. If you need to modify global configuration, you need to configure it in the root project's rstest config or override it through CLI options.
reporters: Global reporters configuration.pool: Global pool configuration.isolate: Global isolate configuration.coverage: Global coverage configuration.bail: Global bail configuration.Project configuration does not inherit the configuration from the root directory. Only the projects field and global configuration in the root directory are effective.
If there are reusable configuration items between your sub-projects, you can extract shared configurations and introduce them in sub-projects respectively:
import { defineConfig, mergeRstestConfig } from '@rstest/core';
import sharedConfig from '../shared/rstest.config';
export default mergeRstestConfig(sharedConfig, {
name: 'pkg-a',
});You can override all project configurations through CLI options.
Rstest supports defining nested projects in sub-project rstest config files. This allows you to define more test projects in sub-projects without defining all projects in the root project.
This is especially useful when your sub-projects need to support multiple test environments or multiple configurations.
For example, define Node.js and browser test environments for packages/pkg-a:
import { defineConfig } from '@rstest/core';
export default defineConfig({
projects: [
{
name: 'node',
include: ['tests/node/**/*.{test,spec}.?(c|m)[jt]s?(x)'],
},
{
name: 'react',
include: ['tests/react/**/*.{test,spec}.?(c|m)[jt]s?(x)'],
testEnvironment: 'jsdom',
},
],
});If you want to view the final effective configuration of Rstest, you can enable debug mode through the DEBUG=rstest environment variable. Rstest will write the final effective Rstest configuration and build configuration to the output directory.
You can filter projects through the --project CLI option, or you can filter specific files under projects by directly filtering file names or file paths.
For more information, please refer to the Test Filtering chapter.