chore: rewrite error message for missing snapshot (#19104)
This commit is contained in:
parent
43a6bf4d45
commit
3d804ff7cd
|
|
@ -27,7 +27,7 @@ test('example test', async ({ page }) => {
|
||||||
|
|
||||||
When you run above for the first time, test runner will say:
|
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 consecutive
|
That's because there was no golden file yet. This method took a bunch of screenshots until two consecutive
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,7 @@ class SnapshotHelper<T extends ImageComparatorOptions> {
|
||||||
|
|
||||||
handleMissingNegated() {
|
handleMissingNegated() {
|
||||||
const isWriteMissingMode = this.updateSnapshots === 'all' || this.updateSnapshots === 'missing';
|
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 {
|
return {
|
||||||
// NOTE: 'isNot' matcher implies inversed value.
|
// NOTE: 'isNot' matcher implies inversed value.
|
||||||
pass: true,
|
pass: true,
|
||||||
|
|
@ -180,7 +180,7 @@ class SnapshotHelper<T extends ImageComparatorOptions> {
|
||||||
writeFileSync(this.snapshotPath, actual);
|
writeFileSync(this.snapshotPath, actual);
|
||||||
writeFileSync(this.actualPath, 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') {
|
if (this.updateSnapshots === 'all') {
|
||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
console.log(message);
|
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.
|
// Fast path: there's no screenshot and we don't intend to update it.
|
||||||
if (helper.updateSnapshots === 'none' && !hasSnapshot)
|
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) {
|
if (!hasSnapshot) {
|
||||||
// Regenerate a new screenshot by waiting until two screenshots are the same.
|
// Regenerate a new screenshot by waiting until two screenshots are the same.
|
||||||
|
|
|
||||||
|
|
@ -216,11 +216,11 @@ test('should write missing expectations locally twice and continue', async ({ ru
|
||||||
expect(result.failed).toBe(1);
|
expect(result.failed).toBe(1);
|
||||||
|
|
||||||
const snapshot1OutputPath = testInfo.outputPath('a.spec.js-snapshots/snapshot.txt');
|
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');
|
expect(fs.readFileSync(snapshot1OutputPath, 'utf-8')).toBe('Hello world');
|
||||||
|
|
||||||
const snapshot2OutputPath = testInfo.outputPath('a.spec.js-snapshots/snapshot2.txt');
|
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(fs.readFileSync(snapshot2OutputPath, 'utf-8')).toBe('Hello world2');
|
||||||
|
|
||||||
expect(result.output).toContain('Here we are!');
|
expect(result.output).toContain('Here we are!');
|
||||||
|
|
@ -243,7 +243,7 @@ test('should not write missing expectations for negated matcher', async ({ runIn
|
||||||
|
|
||||||
expect(result.exitCode).toBe(1);
|
expect(result.exitCode).toBe(1);
|
||||||
const snapshotOutputPath = testInfo.outputPath('a.spec.js-snapshots/snapshot.txt');
|
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);
|
expect(fs.existsSync(snapshotOutputPath)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -323,7 +323,7 @@ test('should silently write missing expectations locally with the update-snapsho
|
||||||
|
|
||||||
expect(result.exitCode).toBe(0);
|
expect(result.exitCode).toBe(0);
|
||||||
const snapshotOutputPath = testInfo.outputPath('a.spec.js-snapshots/snapshot.txt');
|
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);
|
const data = fs.readFileSync(snapshotOutputPath);
|
||||||
expect(data.toString()).toBe(ACTUAL_SNAPSHOT);
|
expect(data.toString()).toBe(ACTUAL_SNAPSHOT);
|
||||||
});
|
});
|
||||||
|
|
@ -341,7 +341,7 @@ test('should silently write missing expectations locally with the update-snapsho
|
||||||
|
|
||||||
expect(result.exitCode).toBe(1);
|
expect(result.exitCode).toBe(1);
|
||||||
const snapshotOutputPath = testInfo.outputPath('a.spec.js-snapshots/snapshot.txt');
|
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);
|
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);
|
expect(result.exitCode).toBe(1);
|
||||||
const snapshotOutputPath = testInfo.outputPath('a.spec.js-snapshots/-snapshot-.txt');
|
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);
|
const data = fs.readFileSync(snapshotOutputPath);
|
||||||
expect(data.toString()).toBe('Hello world');
|
expect(data.toString()).toBe('Hello world');
|
||||||
});
|
});
|
||||||
|
|
@ -768,7 +768,7 @@ test('should update snapshot with array of path segments', async ({ runInlineTes
|
||||||
|
|
||||||
expect(result.exitCode).toBe(0);
|
expect(result.exitCode).toBe(0);
|
||||||
const snapshotOutputPath = testInfo.outputPath('a.spec.js-snapshots/test/path/snapshot.txt');
|
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);
|
const data = fs.readFileSync(snapshotOutputPath);
|
||||||
expect(data.toString()).toBe('Hello world');
|
expect(data.toString()).toBe('Hello world');
|
||||||
});
|
});
|
||||||
|
|
@ -905,7 +905,7 @@ test('should fail with missing expectations and retries', async ({ runInlineTest
|
||||||
expect(result.exitCode).toBe(1);
|
expect(result.exitCode).toBe(1);
|
||||||
expect(result.failed).toBe(1);
|
expect(result.failed).toBe(1);
|
||||||
const snapshotOutputPath = testInfo.outputPath('a.spec.js-snapshots/snapshot.txt');
|
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);
|
const data = fs.readFileSync(snapshotOutputPath);
|
||||||
expect(data.toString()).toBe('Hello world');
|
expect(data.toString()).toBe('Hello world');
|
||||||
});
|
});
|
||||||
|
|
@ -927,7 +927,7 @@ test('should update expectations with retries', async ({ runInlineTest }, testIn
|
||||||
expect(result.exitCode).toBe(0);
|
expect(result.exitCode).toBe(0);
|
||||||
expect(result.passed).toBe(1);
|
expect(result.passed).toBe(1);
|
||||||
const snapshotOutputPath = testInfo.outputPath('a.spec.js-snapshots/snapshot.txt');
|
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);
|
const data = fs.readFileSync(snapshotOutputPath);
|
||||||
expect(data.toString()).toBe('Hello world');
|
expect(data.toString()).toBe('Hello world');
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ test('arg should receive default arg', async ({ runInlineTest }, testInfo) => {
|
||||||
expect(result.exitCode).toBe(0);
|
expect(result.exitCode).toBe(0);
|
||||||
expect(result.passed).toBe(1);
|
expect(result.passed).toBe(1);
|
||||||
const snapshotOutputPath = testInfo.outputPath('__screenshots__/is-a-test-1.png');
|
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);
|
expect(fs.existsSync(snapshotOutputPath)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -557,11 +557,11 @@ test('should write missing expectations locally twice and continue', async ({ ru
|
||||||
expect(result.failed).toBe(1);
|
expect(result.failed).toBe(1);
|
||||||
|
|
||||||
const snapshot1OutputPath = testInfo.outputPath('__screenshots__', 'a.spec.js', 'snapshot.png');
|
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);
|
expect(comparePNGs(fs.readFileSync(snapshot1OutputPath), whiteImage)).toBe(null);
|
||||||
|
|
||||||
const snapshot2OutputPath = testInfo.outputPath('__screenshots__', 'a.spec.js', 'snapshot2.png');
|
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(comparePNGs(fs.readFileSync(snapshot2OutputPath), whiteImage)).toBe(null);
|
||||||
|
|
||||||
expect(result.output).toContain('Here we are!');
|
expect(result.output).toContain('Here we are!');
|
||||||
|
|
@ -585,7 +585,7 @@ test('shouldn\'t write missing expectations locally for negated matcher', async
|
||||||
|
|
||||||
expect(result.exitCode).toBe(1);
|
expect(result.exitCode).toBe(1);
|
||||||
const snapshotOutputPath = testInfo.outputPath('__screenshots__/a.spec.js/snapshot.png');
|
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);
|
expect(fs.existsSync(snapshotOutputPath)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -641,7 +641,7 @@ test('should silently write missing expectations locally with the update-snapsho
|
||||||
|
|
||||||
expect(result.exitCode).toBe(0);
|
expect(result.exitCode).toBe(0);
|
||||||
const snapshotOutputPath = testInfo.outputPath('__screenshots__/a.spec.js/snapshot.png');
|
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);
|
const data = fs.readFileSync(snapshotOutputPath);
|
||||||
expect(comparePNGs(data, whiteImage)).toBe(null);
|
expect(comparePNGs(data, whiteImage)).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
@ -660,7 +660,7 @@ test('should not write missing expectations locally with the update-snapshots fl
|
||||||
|
|
||||||
expect(result.exitCode).toBe(1);
|
expect(result.exitCode).toBe(1);
|
||||||
const snapshotOutputPath = testInfo.outputPath('__screenshots__/a.spec.js/snapshot.png');
|
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);
|
expect(fs.existsSync(snapshotOutputPath)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -996,7 +996,7 @@ test('should fail with missing expectations and retries', async ({ runInlineTest
|
||||||
expect(result.exitCode).toBe(1);
|
expect(result.exitCode).toBe(1);
|
||||||
expect(result.failed).toBe(1);
|
expect(result.failed).toBe(1);
|
||||||
const snapshotOutputPath = testInfo.outputPath('__screenshots__/a.spec.js/snapshot.png');
|
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);
|
const data = fs.readFileSync(snapshotOutputPath);
|
||||||
expect(comparePNGs(data, whiteImage)).toBe(null);
|
expect(comparePNGs(data, whiteImage)).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
@ -1017,7 +1017,7 @@ test('should update expectations with retries', async ({ runInlineTest }, testIn
|
||||||
expect(result.exitCode).toBe(0);
|
expect(result.exitCode).toBe(0);
|
||||||
expect(result.passed).toBe(1);
|
expect(result.passed).toBe(1);
|
||||||
const snapshotOutputPath = testInfo.outputPath('__screenshots__/a.spec.js/snapshot.png');
|
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);
|
const data = fs.readFileSync(snapshotOutputPath);
|
||||||
expect(comparePNGs(data, whiteImage)).toBe(null);
|
expect(comparePNGs(data, whiteImage)).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue