Skip to content

Commit 7b60543

Browse files
nstepienhi-ogawa
andauthored
fix: resolve retry.condition RegExp serialization issue (#9942)
Co-authored-by: Hiroshi Ogawa <hi.ogawa.zz@gmail.com>
1 parent bf89208 commit 7b60543

File tree

3 files changed

+118
-6
lines changed

3 files changed

+118
-6
lines changed

packages/browser/src/client/public/esm-client-injector.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
if (config.testNamePattern)
5151
config.testNamePattern = parseRegexp(config.testNamePattern);
5252

53+
if (config.retry?.condition)
54+
config.retry.condition = parseRegexp(config.retry.condition);
55+
5356
function parseRegexp(input) {
5457
// Parse input
5558
const m = input.match(/(\/?)(.+)\1([a-z]*)/i);

packages/browser/src/node/project.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,15 @@ export class ProjectBrowser implements IProjectBrowser {
129129
}
130130

131131
function wrapConfig(config: SerializedConfig): SerializedConfig {
132-
return {
133-
...config,
134-
// workaround RegExp serialization
135-
testNamePattern: config.testNamePattern
136-
? (config.testNamePattern.toString() as any as RegExp)
137-
: undefined,
132+
config = { ...config }
133+
134+
// workaround RegExp serialization
135+
config.testNamePattern &&= config.testNamePattern.toString() as any as RegExp
136+
137+
// workaround RegExp serialization
138+
if (typeof config.retry === 'object') {
139+
config.retry.condition &&= config.retry.condition.toString() as any as RegExp
138140
}
141+
142+
return config
139143
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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

Comments
 (0)