|
| 1 | +import type { RunVitestConfig } from '#test-utils' |
| 2 | +import { runInlineTests } from '#test-utils' |
| 3 | +import { playwright } from '@vitest/browser-playwright' |
| 4 | +import { expect, it } from 'vitest' |
| 5 | + |
| 6 | +function modeToConfig(mode: string): RunVitestConfig { |
| 7 | + if (mode === 'playwright') { |
| 8 | + return { |
| 9 | + browser: { |
| 10 | + enabled: true, |
| 11 | + headless: true, |
| 12 | + screenshotFailures: false, |
| 13 | + provider: playwright(), |
| 14 | + instances: [{ browser: 'chromium' }], |
| 15 | + }, |
| 16 | + } |
| 17 | + } |
| 18 | + return {} |
| 19 | +} |
| 20 | + |
| 21 | +it.for(['node', 'playwright'])('test.retry.condition is corrrectly serialized %s', async (mode) => { |
| 22 | + const { stderr, errorTree } = await runInlineTests({ |
| 23 | + 'basic.test.js': /* js */` |
| 24 | + import { expect, test } from 'vitest' |
| 25 | +
|
| 26 | + test('task.retry.condition is corrrectly deserialized', ({ task }) => { |
| 27 | + expect(task.retry.condition).toBeInstanceOf(RegExp) |
| 28 | + expect(task.retry.condition).toStrictEqual(/retry_this/) |
| 29 | + }) |
| 30 | +
|
| 31 | + let trial = 0; |
| 32 | + test('retry', () => { |
| 33 | + trial++ |
| 34 | + if (trial === 1) { |
| 35 | + throw new Error('retry_this') |
| 36 | + } |
| 37 | + }) |
| 38 | +
|
| 39 | + let trial2 = 0; |
| 40 | + test('not retry', () => { |
| 41 | + trial2++ |
| 42 | + if (trial2 === 1) { |
| 43 | + throw new Error('retry_that') |
| 44 | + } |
| 45 | + }) |
| 46 | + `, |
| 47 | + }, { |
| 48 | + ...modeToConfig(mode), |
| 49 | + retry: { |
| 50 | + count: 1, |
| 51 | + condition: /retry_this/, |
| 52 | + }, |
| 53 | + }) |
| 54 | + if (mode === 'playwright') { |
| 55 | + expect(stderr).toMatchInlineSnapshot(` |
| 56 | + " |
| 57 | + ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯ |
| 58 | +
|
| 59 | + FAIL |chromium| basic.test.js > not retry |
| 60 | + Error: retry_that |
| 61 | + ❯ basic.test.js:21:17 |
| 62 | + 19| trial2++ |
| 63 | + 20| if (trial2 === 1) { |
| 64 | + 21| throw new Error('retry_that') |
| 65 | + | ^ |
| 66 | + 22| } |
| 67 | + 23| }) |
| 68 | +
|
| 69 | + ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯ |
| 70 | +
|
| 71 | + " |
| 72 | + `) |
| 73 | + } |
| 74 | + else { |
| 75 | + expect(stderr).toMatchInlineSnapshot(` |
| 76 | + " |
| 77 | + ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯ |
| 78 | +
|
| 79 | + FAIL basic.test.js > not retry |
| 80 | + Error: retry_that |
| 81 | + ❯ basic.test.js:21:17 |
| 82 | + 19| trial2++ |
| 83 | + 20| if (trial2 === 1) { |
| 84 | + 21| throw new Error('retry_that') |
| 85 | + | ^ |
| 86 | + 22| } |
| 87 | + 23| }) |
| 88 | +
|
| 89 | + ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯ |
| 90 | +
|
| 91 | + " |
| 92 | + `) |
| 93 | + } |
| 94 | + expect(errorTree()).toMatchInlineSnapshot(` |
| 95 | + { |
| 96 | + "basic.test.js": { |
| 97 | + "not retry": [ |
| 98 | + "retry_that", |
| 99 | + ], |
| 100 | + "retry": "passed", |
| 101 | + "task.retry.condition is corrrectly deserialized": "passed", |
| 102 | + }, |
| 103 | + } |
| 104 | + `) |
| 105 | +}) |
0 commit comments