For AI agents: the complete documentation index is available at https://rstest.rs/zh/llms.txt, the full documentation bundle is available at https://rstest.rs/zh/llms-full.txt, and this page is available as Markdown at https://rstest.rs/zh/config/test/projects.md.
close
  • 简体中文
  • projects

    • 类型:
    import type { ProjectConfig } from '@rstest/core';
    
    type InlineProjectConfig = ProjectConfig & { name: string };
    
    type Projects = (string | InlineProjectConfig)[];
    • 默认值: undefined(将根目录作为单个项目运行)

    在单个 Rstest 进程中运行多个测试项目,并将所有项目的测试结果合并展示。数组中的每一项可以是目录路径、配置文件路径、glob 模式或内联项目配置对象。

    rstest.config.ts
    import { defineConfig, defineInlineProject } from '@rstest/core';
    
    export default defineConfig({
      projects: [
        // Monorepo:每个包目录作为一个 project
        'packages/*',
    
        // 内联项目配置
        defineInlineProject({
          name: 'react',
          include: ['tests/react/**/*.{test,spec}.{js,cjs,mjs,ts,tsx}'],
          testEnvironment: 'jsdom',
        }),
      ],
    });

    projects 数组中的对象项请使用 defineInlineProject()(必须提供 name),项目配置文件的顶层导出请使用 defineProject()(可省略并自动推导 name)。

    如需在命令行只运行特定项目,可传入 --project <name>(支持通配符)。关于目录或 glob 条目、共享配置、全局配置项和嵌套项目,请参考多项目测试。