Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(toMatchSnapshot): use consistent diff colors (#36605)

Pavel Feldman5f4a0c767d09
diff --git a/packages/playwright-core/src/server/utils/comparators.ts b/packages/playwright-core/src/server/utils/comparators.ts
index 06b6bdc6ff..59871ac5ef 100644
--- a/packages/playwright-core/src/server/utils/comparators.ts
+++ b/packages/playwright-core/src/server/utils/comparators.ts
@@ -121,9 +121,9 @@ function compareText(actual: Buffer | string, expectedBuffer: Buffer): Comparato
const lines = diff.createPatch('file', expected, actual, undefined, undefined, { context: 5 }).split('\n');
const coloredLines = lines.slice(4).map(line => {
if (line.startsWith('-'))
- return colors.red(line);
- if (line.startsWith('+'))
return colors.green(line);
+ if (line.startsWith('+'))
+ return colors.red(line);
if (line.startsWith('@@'))
return colors.dim(line);
return line;
diff --git a/tests/playwright-test/golden.spec.ts b/tests/playwright-test/golden.spec.ts
index 83ae3442c7..da6c2a8022 100644
--- a/tests/playwright-test/golden.spec.ts
+++ b/tests/playwright-test/golden.spec.ts
@@ -58,8 +58,8 @@ test('should work with non-txt extensions', async ({ runInlineTest }) => {
`
});
expect(result.exitCode).toBe(1);
- expect(result.rawOutput).toContain(colors.red('-1,2,3'));
- expect(result.rawOutput).toContain(colors.green('+1,2,4'));
+ expect(result.rawOutput).toContain(colors.green('-1,2,3'));
+ expect(result.rawOutput).toContain(colors.red('+1,2,4'));
});
@@ -203,8 +203,8 @@ Line7`,
});
expect(result.exitCode).toBe(1);
expect(result.output).toContain('Line1');
- expect(result.rawOutput).toContain(colors.red('-Line2'));
- expect(result.rawOutput).toContain(colors.green('+Line22'));
+ expect(result.rawOutput).toContain(colors.green('-Line2'));
+ expect(result.rawOutput).toContain(colors.red('+Line22'));
expect(result.output).toContain('Line3');
expect(result.output).toContain('Line5');
expect(result.output).toContain('Line7');
diff --git a/tests/playwright-test/reporter-html.spec.ts b/tests/playwright-test/reporter-html.spec.ts
index 0cef505d20..96c7d916ae 100644
--- a/tests/playwright-test/reporter-html.spec.ts
+++ b/tests/playwright-test/reporter-html.spec.ts
@@ -1227,8 +1227,8 @@ for (const useIntermediateMergeReport of [true, false] as const) {
await showReport();
await page.getByRole('link', { name: 'is a test' }).click();
- await expect(page.locator('.test-error-view').getByText('-old')).toHaveCSS('color', 'rgb(205, 49, 49)');
- await expect(page.locator('.test-error-view').getByText('+new', { exact: true })).toHaveCSS('color', 'rgb(0, 188, 0)');
+ await expect(page.locator('.test-error-view').getByText('-old')).toHaveCSS('color', 'rgb(0, 188, 0)');
+ await expect(page.locator('.test-error-view').getByText('+new', { exact: true })).toHaveCSS('color', 'rgb(205, 49, 49)');
});
test('should highlight inline textual diff in toHaveText', async ({ runInlineTest, showReport, page }) => {