diff --git a/packages/playwright/src/runner/rebase.ts b/packages/playwright/src/runner/rebase.ts index 24f37ca7f7edd..bc59e8374a85d 100644 --- a/packages/playwright/src/runner/rebase.ts +++ b/packages/playwright/src/runner/rebase.ts @@ -83,6 +83,10 @@ export async function applySuggestedRebaselines(config: FullConfigInternal, repo const indent = lines[matcher.loc!.start.line - 1].match(/^\s*/)![0]; const newText = replacement.code.replace(/\{indent\}/g, indent); ranges.push({ start: matcher.start!, end: node.end!, oldText: source.substring(matcher.start!, node.end!), newText }); + // We can have multiple, hopefully equal, replacements for the same location, + // for example when a single test runs multiple times because of projects or retries. + // Do not apply multiple replacements for the same assertion. + break; } } }); diff --git a/tests/playwright-test/update-aria-snapshot.spec.ts b/tests/playwright-test/update-aria-snapshot.spec.ts index 57424b7bc6568..63769f8408455 100644 --- a/tests/playwright-test/update-aria-snapshot.spec.ts +++ b/tests/playwright-test/update-aria-snapshot.spec.ts @@ -24,12 +24,15 @@ function trimPatch(patch: string) { return patch.split('\n').map(line => line.trimEnd()).join('\n'); } -test('should update snapshot with the update-snapshots flag', async ({ runInlineTest }, testInfo) => { +test('should update snapshot with the update-snapshots flag with multiple projects', async ({ runInlineTest }, testInfo) => { const result = await runInlineTest({ + 'playwright.config.ts': ` + export default { projects: [{ name: 'p1' }, { name: 'p2' }] }; + `, 'a.spec.ts': ` import { test, expect } from '@playwright/test'; test('test', async ({ page }) => { - await page.setContent(\`