Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: rewrite error message for missing snapshot (#19104)
Shubham Kanodia3d804ff7cd3f
diff --git a/docs/src/test-snapshots-js.md b/docs/src/test-snapshots-js.mdindex 34f2f28d05..8c48a6641d 100644--- a/docs/src/test-snapshots-js.md+++ b/docs/src/test-snapshots-js.md@@ -27,7 +27,7 @@ test('example test', async ({ page }) => {When you run above for the first time, test runner will say:```-Error: example.spec.ts-snapshots/example-test-1-chromium-darwin.png is missing in snapshots, writing actual.+Error: A snapshot doesn't exist at example.spec.ts-snapshots/example-test-1-chromium-darwin.png, writing actual.```That's because there was no golden file yet. This method took a bunch of screenshots until two consecutivediff --git a/packages/playwright-test/src/matchers/toMatchSnapshot.ts b/packages/playwright-test/src/matchers/toMatchSnapshot.tsindex e07764ae66..ba4b21952a 100644--- a/packages/playwright-test/src/matchers/toMatchSnapshot.ts+++ b/packages/playwright-test/src/matchers/toMatchSnapshot.ts@@ -151,7 +151,7 @@ class SnapshotHelper<T extends ImageComparatorOptions> {handleMissingNegated() {const isWriteMissingMode = this.updateSnapshots === 'all' || this.updateSnapshots === 'missing';- const message = `${this.snapshotPath} is missing in snapshots${isWriteMissingMode ? ', matchers using ".not" won\'t write them automatically.' : '.'}`;+ const message = `A snapshot doesn't exist at ${this.snapshotPath}${isWriteMissingMode ? ', matchers using ".not" won\'t write them automatically.' : '.'}`;return {// NOTE: 'isNot' matcher implies inversed value.pass: true,@@ -180,7 +180,7 @@ class SnapshotHelper<T extends ImageComparatorOptions> {writeFileSync(this.snapshotPath, actual);writeFileSync(this.actualPath, actual);}- const message = `${this.snapshotPath} is missing in snapshots${isWriteMissingMode ? ', writing actual.' : '.'}`;+ const message = `A snapshot doesn't exist at ${this.snapshotPath}${isWriteMissingMode ? ', writing actual.' : '.'}`;if (this.updateSnapshots === 'all') {/* eslint-disable no-console */console.log(message);@@ -349,7 +349,7 @@ export async function toHaveScreenshot(// Fast path: there's no screenshot and we don't intend to update it.if (helper.updateSnapshots === 'none' && !hasSnapshot)- return { pass: false, message: () => `${helper.snapshotPath} is missing in snapshots.` };+ return { pass: false, message: () => `A snapshot doesn't exist at ${helper.snapshotPath}.` };if (!hasSnapshot) {// Regenerate a new screenshot by waiting until two screenshots are the same.diff --git a/tests/playwright-test/golden.spec.ts b/tests/playwright-test/golden.spec.tsindex afd61657ac..8cb05152f2 100644--- a/tests/playwright-test/golden.spec.ts+++ b/tests/playwright-test/golden.spec.ts@@ -216,11 +216,11 @@ test('should write missing expectations locally twice and continue', async ({ ruexpect(result.failed).toBe(1);const snapshot1OutputPath = testInfo.outputPath('a.spec.js-snapshots/snapshot.txt');- expect(result.output).toContain(`Error: ${snapshot1OutputPath} is missing in snapshots, writing actual`);+ expect(result.output).toContain(`Error: A snapshot doesn't exist at ${snapshot1OutputPath}, writing actual`);expect(fs.readFileSync(snapshot1OutputPath, 'utf-8')).toBe('Hello world');const snapshot2OutputPath = testInfo.outputPath('a.spec.js-snapshots/snapshot2.txt');- expect(result.output).toContain(`Error: ${snapshot2OutputPath} is missing in snapshots, writing actual`);+ expect(result.output).toContain(`Error: A snapshot doesn't exist at ${snapshot2OutputPath}, writing actual`);expect(fs.readFileSync(snapshot2OutputPath, 'utf-8')).toBe('Hello world2');expect(result.output).toContain('Here we are!');@@ -243,7 +243,7 @@ test('should not write missing expectations for negated matcher', async ({ runInexpect(result.exitCode).toBe(1);const snapshotOutputPath = testInfo.outputPath('a.spec.js-snapshots/snapshot.txt');- expect(result.output).toContain(`${snapshotOutputPath} is missing in snapshots, matchers using ".not" won\'t write them automatically.`);+ expect(result.output).toContain(`A snapshot doesn't exist at ${snapshotOutputPath}, matchers using ".not" won\'t write them automatically.`);expect(fs.existsSync(snapshotOutputPath)).toBe(false);});@@ -323,7 +323,7 @@ test('should silently write missing expectations locally with the update-snapshoexpect(result.exitCode).toBe(0);const snapshotOutputPath = testInfo.outputPath('a.spec.js-snapshots/snapshot.txt');- expect(result.output).toContain(`${snapshotOutputPath} is missing in snapshots, writing actual`);+ expect(result.output).toContain(`A snapshot doesn't exist at ${snapshotOutputPath}, writing actual`);const data = fs.readFileSync(snapshotOutputPath);expect(data.toString()).toBe(ACTUAL_SNAPSHOT);});@@ -341,7 +341,7 @@ test('should silently write missing expectations locally with the update-snapshoexpect(result.exitCode).toBe(1);const snapshotOutputPath = testInfo.outputPath('a.spec.js-snapshots/snapshot.txt');- expect(result.output).toContain(`${snapshotOutputPath} is missing in snapshots, matchers using ".not" won\'t write them automatically.`);+ expect(result.output).toContain(`A snapshot doesn't exist at ${snapshotOutputPath}, matchers using ".not" won\'t write them automatically.`);expect(fs.existsSync(snapshotOutputPath)).toBe(false);});@@ -647,7 +647,7 @@ test('should write missing expectations with sanitized snapshot name', async ({expect(result.exitCode).toBe(1);const snapshotOutputPath = testInfo.outputPath('a.spec.js-snapshots/-snapshot-.txt');- expect(result.output).toContain(`${snapshotOutputPath} is missing in snapshots, writing actual`);+ expect(result.output).toContain(`A snapshot doesn't exist at ${snapshotOutputPath}, writing actual`);const data = fs.readFileSync(snapshotOutputPath);expect(data.toString()).toBe('Hello world');});@@ -768,7 +768,7 @@ test('should update snapshot with array of path segments', async ({ runInlineTesexpect(result.exitCode).toBe(0);const snapshotOutputPath = testInfo.outputPath('a.spec.js-snapshots/test/path/snapshot.txt');- expect(result.output).toContain(`${snapshotOutputPath} is missing in snapshots, writing actual`);+ expect(result.output).toContain(`A snapshot doesn't exist at ${snapshotOutputPath}, writing actual`);const data = fs.readFileSync(snapshotOutputPath);expect(data.toString()).toBe('Hello world');});@@ -905,7 +905,7 @@ test('should fail with missing expectations and retries', async ({ runInlineTestexpect(result.exitCode).toBe(1);expect(result.failed).toBe(1);const snapshotOutputPath = testInfo.outputPath('a.spec.js-snapshots/snapshot.txt');- expect(result.output).toContain(`${snapshotOutputPath} is missing in snapshots, writing actual`);+ expect(result.output).toContain(`A snapshot doesn't exist at ${snapshotOutputPath}, writing actual`);const data = fs.readFileSync(snapshotOutputPath);expect(data.toString()).toBe('Hello world');});@@ -927,7 +927,7 @@ test('should update expectations with retries', async ({ runInlineTest }, testInexpect(result.exitCode).toBe(0);expect(result.passed).toBe(1);const snapshotOutputPath = testInfo.outputPath('a.spec.js-snapshots/snapshot.txt');- expect(result.output).toContain(`${snapshotOutputPath} is missing in snapshots, writing actual`);+ expect(result.output).toContain(`A snapshot doesn't exist at ${snapshotOutputPath}, writing actual`);const data = fs.readFileSync(snapshotOutputPath);expect(data.toString()).toBe('Hello world');});diff --git a/tests/playwright-test/snapshot-path-template.spec.ts b/tests/playwright-test/snapshot-path-template.spec.tsindex 97d44220d1..d8860b1614 100644--- a/tests/playwright-test/snapshot-path-template.spec.ts+++ b/tests/playwright-test/snapshot-path-template.spec.ts@@ -132,7 +132,7 @@ test('arg should receive default arg', async ({ runInlineTest }, testInfo) => {expect(result.exitCode).toBe(0);expect(result.passed).toBe(1);const snapshotOutputPath = testInfo.outputPath('__screenshots__/is-a-test-1.png');- expect(result.output).toContain(`${snapshotOutputPath} is missing in snapshots, writing actual`);+ expect(result.output).toContain(`A snapshot doesn't exist at ${snapshotOutputPath}, writing actual`);expect(fs.existsSync(snapshotOutputPath)).toBe(true);});diff --git a/tests/playwright-test/to-have-screenshot.spec.ts b/tests/playwright-test/to-have-screenshot.spec.tsindex 3536df2531..0436b49b1c 100644--- a/tests/playwright-test/to-have-screenshot.spec.ts+++ b/tests/playwright-test/to-have-screenshot.spec.ts@@ -557,11 +557,11 @@ test('should write missing expectations locally twice and continue', async ({ ruexpect(result.failed).toBe(1);const snapshot1OutputPath = testInfo.outputPath('__screenshots__', 'a.spec.js', 'snapshot.png');- expect(result.output).toContain(`Error: ${snapshot1OutputPath} is missing in snapshots, writing actual`);+ expect(result.output).toContain(`Error: A snapshot doesn't exist at ${snapshot1OutputPath}, writing actual`);expect(comparePNGs(fs.readFileSync(snapshot1OutputPath), whiteImage)).toBe(null);const snapshot2OutputPath = testInfo.outputPath('__screenshots__', 'a.spec.js', 'snapshot2.png');- expect(result.output).toContain(`Error: ${snapshot2OutputPath} is missing in snapshots, writing actual`);+ expect(result.output).toContain(`Error: A snapshot doesn't exist at ${snapshot2OutputPath}, writing actual`);expect(comparePNGs(fs.readFileSync(snapshot2OutputPath), whiteImage)).toBe(null);expect(result.output).toContain('Here we are!');@@ -585,7 +585,7 @@ test('shouldn\'t write missing expectations locally for negated matcher', asyncexpect(result.exitCode).toBe(1);const snapshotOutputPath = testInfo.outputPath('__screenshots__/a.spec.js/snapshot.png');- expect(result.output).toContain(`${snapshotOutputPath} is missing in snapshots, matchers using ".not" won\'t write them automatically.`);+ expect(result.output).toContain(`A snapshot doesn't exist at ${snapshotOutputPath}, matchers using ".not" won\'t write them automatically.`);expect(fs.existsSync(snapshotOutputPath)).toBe(false);});@@ -641,7 +641,7 @@ test('should silently write missing expectations locally with the update-snapshoexpect(result.exitCode).toBe(0);const snapshotOutputPath = testInfo.outputPath('__screenshots__/a.spec.js/snapshot.png');- expect(result.output).toContain(`${snapshotOutputPath} is missing in snapshots, writing actual`);+ expect(result.output).toContain(`A snapshot doesn't exist at ${snapshotOutputPath}, writing actual`);const data = fs.readFileSync(snapshotOutputPath);expect(comparePNGs(data, whiteImage)).toBe(null);});@@ -660,7 +660,7 @@ test('should not write missing expectations locally with the update-snapshots flexpect(result.exitCode).toBe(1);const snapshotOutputPath = testInfo.outputPath('__screenshots__/a.spec.js/snapshot.png');- expect(result.output).toContain(`${snapshotOutputPath} is missing in snapshots, matchers using ".not" won\'t write them automatically.`);+ expect(result.output).toContain(`A snapshot doesn't exist at ${snapshotOutputPath}, matchers using ".not" won\'t write them automatically.`);expect(fs.existsSync(snapshotOutputPath)).toBe(false);});@@ -996,7 +996,7 @@ test('should fail with missing expectations and retries', async ({ runInlineTestexpect(result.exitCode).toBe(1);expect(result.failed).toBe(1);const snapshotOutputPath = testInfo.outputPath('__screenshots__/a.spec.js/snapshot.png');- expect(result.output).toContain(`${snapshotOutputPath} is missing in snapshots, writing actual`);+ expect(result.output).toContain(`A snapshot doesn't exist at ${snapshotOutputPath}, writing actual`);const data = fs.readFileSync(snapshotOutputPath);expect(comparePNGs(data, whiteImage)).toBe(null);});@@ -1017,7 +1017,7 @@ test('should update expectations with retries', async ({ runInlineTest }, testInexpect(result.exitCode).toBe(0);expect(result.passed).toBe(1);const snapshotOutputPath = testInfo.outputPath('__screenshots__/a.spec.js/snapshot.png');- expect(result.output).toContain(`${snapshotOutputPath} is missing in snapshots, writing actual`);+ expect(result.output).toContain(`A snapshot doesn't exist at ${snapshotOutputPath}, writing actual`);const data = fs.readFileSync(snapshotOutputPath);expect(comparePNGs(data, whiteImage)).toBe(null);});