From e24780f825c1f18140384b95b563958d2f956e0a Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Fri, 15 Nov 2024 12:47:25 -0800 Subject: [PATCH] chore: unshift shortest whitespace prefix only (#33618) --- .../playwright/src/matchers/toMatchAriaSnapshot.ts | 1 - tests/page/page-aria-snapshot.spec.ts | 1 - tests/page/to-match-aria-snapshot.spec.ts | 14 ++++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/playwright/src/matchers/toMatchAriaSnapshot.ts b/packages/playwright/src/matchers/toMatchAriaSnapshot.ts index f3e7d47a6e..0bb600f7b0 100644 --- a/packages/playwright/src/matchers/toMatchAriaSnapshot.ts +++ b/packages/playwright/src/matchers/toMatchAriaSnapshot.ts @@ -126,7 +126,6 @@ function unshift(snapshot: string): string { const match = line.match(/^(\s*)/); if (match && match[1].length < whitespacePrefixLength) whitespacePrefixLength = match[1].length; - break; } return lines.filter(t => t.trim()).map(line => line.substring(whitespacePrefixLength)).join('\n'); } diff --git a/tests/page/page-aria-snapshot.spec.ts b/tests/page/page-aria-snapshot.spec.ts index a7937e9be5..fe0de8cb9e 100644 --- a/tests/page/page-aria-snapshot.spec.ts +++ b/tests/page/page-aria-snapshot.spec.ts @@ -27,7 +27,6 @@ function unshift(snapshot: string): string { const match = line.match(/^(\s*)/); if (match && match[1].length < whitespacePrefixLength) whitespacePrefixLength = match[1].length; - break; } return lines.filter(t => t.trim()).map(line => line.substring(whitespacePrefixLength)).join('\n'); } diff --git a/tests/page/to-match-aria-snapshot.spec.ts b/tests/page/to-match-aria-snapshot.spec.ts index 05a02f369b..3961d6ad0a 100644 --- a/tests/page/to-match-aria-snapshot.spec.ts +++ b/tests/page/to-match-aria-snapshot.spec.ts @@ -659,3 +659,17 @@ test('should parse attributes', async ({ page }) => { `); } }); + +test('should not unshift actual template text', async ({ page }) => { + await page.setContent(` +

title

+

title 2

+ `); + const error = await expect(page.locator('body')).toMatchAriaSnapshot(` + - heading "title" [level=1] + - heading "title 2" [level=1] + `, { timeout: 1000 }).catch(e => e); + expect(stripAnsi(error.message)).toContain(` + - heading "title" [level=1] +- heading "title 2" [level=1]`); +});