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/max-concurrency.md.
close
  • 简体中文
  • maxConcurrency

    • 类型: number
    • 默认值: 5
    • CLI: --maxConcurrency=10

    使用 test.concurrent 或 describe.concurrent 时,限制单个测试文件内同时运行的测试用例数量。超过限制的用例会等待空位后再运行。

    设置 sequence.hooks: 'parallel' 后,此值也限制单个文件内生命周期 Hook 和返回的清理函数的并发数。Hook 与测试用例分别计数。

    增大这个值不会让普通的 test() 用例并发执行。需要先将测试或其所属 suite 标记为 concurrent。

    配置控制什么不控制什么
    pool.maxWorkers并行运行 Node.js 测试文件的 worker 数量文件内的并发用例数量
    maxConcurrency每个测试文件内的并发用例数量并行运行的文件数量
    isolate文件之间是否共享模块状态和测试环境同时运行的测试数量

    例如,pool.maxWorkers: 1 会让 Node.js 测试文件逐个运行,但每个文件内仍然可以并发执行多个 test.concurrent 用例。如果这些用例也需要逐个执行,还应设置 maxConcurrency: 1。

    CLI
    rstest.config.ts
    npx rstest --maxConcurrency=10