Skip to content

Commit

Permalink
test: using a separate fixture to test retry
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryZhang-ZHY committed Jun 19, 2023
1 parent e2256fd commit df8192a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 15 deletions.
10 changes: 10 additions & 0 deletions test/config/fixtures/retry/retry.test.ts
@@ -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
@@ -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
@@ -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')
})
})
14 changes: 0 additions & 14 deletions test/core/test/retry.test.ts
Expand Up @@ -64,17 +64,3 @@ describe.each([
expect(flag3).toBe(false)
})
}, { retry: 2 })

describe('global retry', () => {
let count6 = 0
let count7 = 0
it('test should inherit options from the global config if missing', () => {
count6 += 1
expect(count6).toBe(3)
})

it('test should not inherit options from the global config if exists', () => {
count7 += 1
expect(count7).toBe(5)
}, { retry: 5 })
})
1 change: 0 additions & 1 deletion test/core/vitest.config.ts
Expand Up @@ -46,7 +46,6 @@ export default defineConfig({
exclude: ['**/fixtures/**', ...defaultExclude],
slowTestThreshold: 1000,
testTimeout: 2000,
retry: 3,
setupFiles: [
'./test/setup.ts',
],
Expand Down

0 comments on commit df8192a

Please sign in to comment.