diff --git a/docs/config/index.md b/docs/config/index.md index fc30c1895..e80739854 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -1452,3 +1452,12 @@ This config option affects truncating values in `test.each` titles and inside th Stop test execution when given number of tests have failed. By default Vitest will run all of your test cases even if some of them fail. This may not be desired for CI builds where you are only interested in 100% successful builds and would like to stop test execution as early as possible when test failures occur. The `bail` option can be used to speed up CI runs by preventing it from running more tests when failures have occured. + +### retry + +- **Type:** `number` +- **Default:** `0` +- **CLI:** `--retry=` +- **Version:** Since Vitest 0.32.3 + +Retry the test specific number of times if it fails. diff --git a/docs/guide/cli.md b/docs/guide/cli.md index b13e93804..84f5d0704 100644 --- a/docs/guide/cli.md +++ b/docs/guide/cli.md @@ -93,6 +93,7 @@ Run only [benchmark](https://vitest.dev/guide/features.html#benchmarking-experim | `--inspect` | Enables Node.js inspector | | `--inspect-brk` | Enables Node.js inspector with break | | `--bail ` | Stop test execution when given number of tests have failed | +| `--retry ` | Retry the test specific number of times if it fails | | `-h, --help` | Display available CLI options | ::: tip diff --git a/packages/runner/src/suite.ts b/packages/runner/src/suite.ts index 787db6029..615d0d83e 100644 --- a/packages/runner/src/suite.ts +++ b/packages/runner/src/suite.ts @@ -78,7 +78,7 @@ function createSuiteCollector(name: string, factory: SuiteFactory = () => { }, m mode, suite: undefined!, fails: this.fails, - retry: options?.retry, + retry: options?.retry ?? runner.config.retry, repeats: options?.repeats, meta: Object.create(null), } as Omit as Test diff --git a/packages/runner/src/types/runner.ts b/packages/runner/src/types/runner.ts index 6183bb606..eb1ee9edb 100644 --- a/packages/runner/src/types/runner.ts +++ b/packages/runner/src/types/runner.ts @@ -20,6 +20,7 @@ export interface VitestRunnerConfig { maxConcurrency: number testTimeout: number hookTimeout: number + retry: number } export type VitestRunnerImportSource = 'collect' | 'setup' diff --git a/packages/vitest/src/node/cli.ts b/packages/vitest/src/node/cli.ts index fe18091b5..f8d16d7b3 100644 --- a/packages/vitest/src/node/cli.ts +++ b/packages/vitest/src/node/cli.ts @@ -48,6 +48,7 @@ cli .option('--inspect-brk', 'Enable Node.js inspector with break') .option('--test-timeout