close
  • 简体中文
  • retry

    • 类型: number
    • 默认值: 0
    • CLI: --retry <times>

    如果测试执行失败,则重试特定次数。这对于一些会产生不稳定结果的测试用例很有帮助。

    单个测试可以通过 TestOptions.retry 覆盖该配置;传入 { retry: 0 } 即可在保留全局 retry 的同时为某个测试关闭重试。

    示例

    你可以通过设置 retry: 2 来指定测试失败后重试两次:

    CLI
    rstest.config.ts
    npx rstest --retry 2

    当测试重试时,Rstest 会打印如下日志:

    • 当测试成功时:
     retry.test.ts (1)
     should run success with retry (6ms) (retry x2)
    
     Test Files 1 passed
          Tests 1 passed
       Duration 146 ms (build 22 ms, tests 124 ms)
    • 失败时:
     retry.test.ts (1)
     should run success with retry (6ms) (retry x2)
        expected 1 to be 5 // Object.is equality
        expected 2 to be 5 // Object.is equality
        expected 3 to be 5 // Object.is equality
    
     ...
    
     Test Files 1 failed
          Tests 1 failed
       Duration 171 ms (build 23 ms, tests 148 ms)