type ProjectConfig = Omit<
RstestConfig,
'projects' | 'reporters' | 'pool' | 'isolate' | 'coverage' | 'bail'
>;
type Projects = (string | ProjectConfig)[];[<rootDir>]定义多个测试项目,可以是一个目录、配置文件或 glob 模式,也可以是一个对象。 Rstest 将会按照各个项目定义的配置运行对应的测试,所有项目的测试结果将会合并展示。
你可以通过 --project 选项来过滤运行特定项目。
如果没有 projects 字段,rstest 会将当前目录视为单个项目。
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',
},
],
});需要注意的是:
reporters、pool、isolate 等,在 project 配置中是无效的projectsimport { defineConfig } from '@rstest/core';
import sharedConfig from '../shared/rstest.config';
export default defineConfig({
...sharedConfig,
});Rstest 支持在 projects 字段中直接通过内联的方式配置 project。这允许你在单个项目下定义多个测试项目,而无需为每个测试项目创建单独的配置文件。
import { defineConfig } from '@rstest/core';
export default defineConfig({
projects: [
// 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',
},
],
});