Skip to content

Commit cb0f456

Browse files
authored
cherry-pick(#33629): fix(rebase): do not apply multiple rebaselines to the same assertion (#33630)
1 parent 698823a commit cb0f456

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

packages/playwright/src/runner/rebase.ts

+4
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ export async function applySuggestedRebaselines(config: FullConfigInternal, repo
8383
const indent = lines[matcher.loc!.start.line - 1].match(/^\s*/)![0];
8484
const newText = replacement.code.replace(/\{indent\}/g, indent);
8585
ranges.push({ start: matcher.start!, end: node.end!, oldText: source.substring(matcher.start!, node.end!), newText });
86+
// We can have multiple, hopefully equal, replacements for the same location,
87+
// for example when a single test runs multiple times because of projects or retries.
88+
// Do not apply multiple replacements for the same assertion.
89+
break;
8690
}
8791
}
8892
});

tests/playwright-test/update-aria-snapshot.spec.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@ function trimPatch(patch: string) {
2424
return patch.split('\n').map(line => line.trimEnd()).join('\n');
2525
}
2626

27-
test('should update snapshot with the update-snapshots flag', async ({ runInlineTest }, testInfo) => {
27+
test('should update snapshot with the update-snapshots flag with multiple projects', async ({ runInlineTest }, testInfo) => {
2828
const result = await runInlineTest({
29+
'playwright.config.ts': `
30+
export default { projects: [{ name: 'p1' }, { name: 'p2' }] };
31+
`,
2932
'a.spec.ts': `
3033
import { test, expect } from '@playwright/test';
3134
test('test', async ({ page }) => {
32-
await page.setContent(\`<h1>hello</h1>\`);
35+
await page.setContent(\`<h1>hello</h1><h2>bye</h2>\`);
3336
await expect(page.locator('body')).toMatchAriaSnapshot(\`
3437
- heading "world"
3538
\`);
@@ -43,12 +46,13 @@ test('should update snapshot with the update-snapshots flag', async ({ runInline
4346
expect(trimPatch(data)).toBe(`diff --git a/a.spec.ts b/a.spec.ts
4447
--- a/a.spec.ts
4548
+++ b/a.spec.ts
46-
@@ -3,7 +3,7 @@
49+
@@ -3,7 +3,8 @@
4750
test('test', async ({ page }) => {
48-
await page.setContent(\`<h1>hello</h1>\`);
51+
await page.setContent(\`<h1>hello</h1><h2>bye</h2>\`);
4952
await expect(page.locator('body')).toMatchAriaSnapshot(\`
5053
- - heading "world"
5154
+ - heading "hello" [level=1]
55+
+ - heading "bye" [level=2]
5256
\`);
5357
});
5458

0 commit comments

Comments
 (0)