fix(toHaveScreenshot): don't exit with 1 with updateSnapshot: missing
This commit is contained in:
parent
bc27ca225e
commit
d9a609b460
|
|
@ -226,7 +226,7 @@ class SnapshotHelper {
|
||||||
this.testInfo.attachments.push({ name: addSuffixToFilePath(this.outputBaseName, '-actual'), contentType: this.mimeType, path: this.actualPath });
|
this.testInfo.attachments.push({ name: addSuffixToFilePath(this.outputBaseName, '-actual'), contentType: this.mimeType, path: this.actualPath });
|
||||||
}
|
}
|
||||||
const message = `A snapshot doesn't exist at ${this.snapshotPath}${isWriteMissingMode ? ', writing actual.' : '.'}`;
|
const message = `A snapshot doesn't exist at ${this.snapshotPath}${isWriteMissingMode ? ', writing actual.' : '.'}`;
|
||||||
if (this.updateSnapshots === 'all') {
|
if (['all', 'missing'].includes(this.updateSnapshots)) {
|
||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
console.log(message);
|
console.log(message);
|
||||||
return this.createMatcherResult(message, true);
|
return this.createMatcherResult(message, true);
|
||||||
|
|
|
||||||
|
|
@ -1150,6 +1150,80 @@ test('should update expectations with retries', async ({ runInlineTest }, testIn
|
||||||
expect(comparePNGs(data, whiteImage)).toBe(null);
|
expect(comparePNGs(data, whiteImage)).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should update expectations with updateSnapshot: all config option', async ({ runInlineTest }, testInfo) => {
|
||||||
|
const result = await runInlineTest({
|
||||||
|
...playwrightConfig({
|
||||||
|
updateSnapshots: 'all',
|
||||||
|
snapshotPathTemplate: '__screenshots__/{testFilePath}/{arg}{ext}',
|
||||||
|
}),
|
||||||
|
'a.spec.js': `
|
||||||
|
const { test, expect } = require('@playwright/test');
|
||||||
|
test('is a test', async ({ page }) => {
|
||||||
|
await expect(page).toHaveScreenshot('snapshot.png');
|
||||||
|
});
|
||||||
|
`
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.exitCode).toBe(0);
|
||||||
|
expect(result.passed).toBe(1);
|
||||||
|
const snapshotOutputPath = testInfo.outputPath('__screenshots__/a.spec.js/snapshot.png');
|
||||||
|
expect(result.output).toContain(`A snapshot doesn't exist at ${snapshotOutputPath}, writing actual`);
|
||||||
|
const data = fs.readFileSync(snapshotOutputPath);
|
||||||
|
expect(comparePNGs(data, whiteImage)).toBe(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should update expectations with updateSnapshot: missing config option', async ({ runInlineTest }, testInfo) => {
|
||||||
|
const result = await runInlineTest({
|
||||||
|
...playwrightConfig({
|
||||||
|
updateSnapshots: 'missing',
|
||||||
|
snapshotPathTemplate: '__screenshots__/{testFilePath}/{arg}{ext}',
|
||||||
|
}),
|
||||||
|
'a.spec.js': `
|
||||||
|
const { test, expect } = require('@playwright/test');
|
||||||
|
test('is a test', async ({ page }) => {
|
||||||
|
await expect(page).toHaveScreenshot('snapshot.png');
|
||||||
|
});
|
||||||
|
`
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.exitCode).toBe(0);
|
||||||
|
expect(result.passed).toBe(1);
|
||||||
|
const snapshotOutputPath = testInfo.outputPath('__screenshots__/a.spec.js/snapshot.png');
|
||||||
|
expect(result.output).toContain(`A snapshot doesn't exist at ${snapshotOutputPath}, writing actual`);
|
||||||
|
const data = fs.readFileSync(snapshotOutputPath);
|
||||||
|
expect(comparePNGs(data, whiteImage)).toBe(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should update expectations with updateSnapshot: missing config option and throw for changed ones', async ({ runInlineTest }, testInfo) => {
|
||||||
|
const result = await runInlineTest({
|
||||||
|
...playwrightConfig({
|
||||||
|
updateSnapshots: 'missing',
|
||||||
|
snapshotPathTemplate: '__screenshots__/{testFilePath}/{arg}{ext}',
|
||||||
|
}),
|
||||||
|
'passed.spec.js': `
|
||||||
|
const { test, expect } = require('@playwright/test');
|
||||||
|
test('is a test', async ({ page }) => {
|
||||||
|
await expect(page).toHaveScreenshot('snapshot.png');
|
||||||
|
});
|
||||||
|
`,
|
||||||
|
'failing.spec.js': `
|
||||||
|
const { test, expect } = require('@playwright/test');
|
||||||
|
test('is a test', async ({ page }) => {
|
||||||
|
await expect(page).toHaveScreenshot('exists.png');
|
||||||
|
});
|
||||||
|
`,
|
||||||
|
'__screenshots__/failing.spec.js/exists.png': redImage,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.exitCode).toBe(1);
|
||||||
|
expect(result.passed).toBe(1);
|
||||||
|
expect(result.failed).toBe(1);
|
||||||
|
const snapshotOutputPath = testInfo.outputPath('__screenshots__/passed.spec.js/snapshot.png');
|
||||||
|
expect(result.output).toContain(`A snapshot doesn't exist at ${snapshotOutputPath}, writing actual`);
|
||||||
|
const data = fs.readFileSync(snapshotOutputPath);
|
||||||
|
expect(comparePNGs(data, whiteImage)).toBe(null);
|
||||||
|
});
|
||||||
|
|
||||||
test('should respect comparator name', async ({ runInlineTest }) => {
|
test('should respect comparator name', async ({ runInlineTest }) => {
|
||||||
const expected = fs.readFileSync(path.join(__dirname, '../image_tools/fixtures/should-match/tiny-antialiasing-sample/tiny-expected.png'));
|
const expected = fs.readFileSync(path.join(__dirname, '../image_tools/fixtures/should-match/tiny-antialiasing-sample/tiny-expected.png'));
|
||||||
const actualURL = pathToFileURL(path.join(__dirname, '../image_tools/fixtures/should-match/tiny-antialiasing-sample/tiny-actual.png'));
|
const actualURL = pathToFileURL(path.join(__dirname, '../image_tools/fixtures/should-match/tiny-antialiasing-sample/tiny-actual.png'));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue