Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(retry): support retry in config and cli #3602

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/runner/src/suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,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<Test, 'context'> as Test
Expand Down
1 change: 1 addition & 0 deletions packages/runner/src/types/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface VitestRunnerConfig {
maxConcurrency: number
testTimeout: number
hookTimeout: number
retry: number
}

export type VitestRunnerImportSource = 'collect' | 'setup'
Expand Down
1 change: 1 addition & 0 deletions packages/vitest/src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ cli
.option('--inspect', 'Enable Node.js inspector')
.option('--inspect-brk', 'Enable Node.js inspector with break')
.option('--test-timeout <time>', 'Default timeout of a test in milliseconds (default: 5000)')
.option('--retry <times>', 'Number of retries (default: 1)')
.option('--bail <number>', 'Stop test execution when given number of tests have failed', { default: 0 })
.help()

Expand Down
6 changes: 5 additions & 1 deletion packages/vitest/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,11 @@ export interface InlineConfig {
* @default 1000
*/
teardownTimeout?: number

/**
* Number of retries
* @default 1
*/
retry?: number
/**
* Silent mode
*
Expand Down
10 changes: 10 additions & 0 deletions test/config/fixtures/retry/retry.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { expect, test } from 'vitest'

let number = 0
test('should passed', () => {
expect(number++).toBe(3)
})

test('retry but still failed', () => {
expect(number++).toBe(4)
})
8 changes: 8 additions & 0 deletions test/config/fixtures/retry/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
include: ['*.test.ts'],
retry: 4,
},
})
26 changes: 26 additions & 0 deletions test/config/test/retry.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import path from 'node:path'
import { describe, expect, test } from 'vitest'
import { runVitest } from '../../test-utils'

const root = path.resolve('./fixtures/retry')
function run(testNamePattern?: string) {
return runVitest({
root,
testNamePattern,
})
}

describe('retry', () => {
test('should passed', async () => {
const { stdout } = await run('should passed')
expect(stdout).toContain('1 passed')
})

test('retry but still failed', async () => {
const { stdout } = await run('retry but still failed')
expect(stdout).toContain('expected 1 to be 4')
expect(stdout).toContain('expected 2 to be 4')
expect(stdout).toContain('expected 3 to be 4')
expect(stdout).toContain('1 failed')
})
})