fix(snapshots): --update-snapshots + retries should work (#9799)
This commit is contained in:
parent
273122b761
commit
22e4a0d580
|
|
@ -45,12 +45,15 @@ export function toMatchSnapshot(this: ReturnType<Expect['getState']>, received:
|
||||||
// sanitizes path if string
|
// sanitizes path if string
|
||||||
const pathSegments = Array.isArray(options.name) ? options.name : [addSuffixToFilePath(options.name, '', undefined, true)];
|
const pathSegments = Array.isArray(options.name) ? options.name : [addSuffixToFilePath(options.name, '', undefined, true)];
|
||||||
const withNegateComparison = this.isNot;
|
const withNegateComparison = this.isNot;
|
||||||
|
let updateSnapshots = testInfo.config.updateSnapshots;
|
||||||
|
if (updateSnapshots === 'missing' && testInfo.retry < testInfo.project.retries)
|
||||||
|
updateSnapshots = 'none';
|
||||||
const { pass, message, expectedPath, actualPath, diffPath, mimeType } = compare(
|
const { pass, message, expectedPath, actualPath, diffPath, mimeType } = compare(
|
||||||
received,
|
received,
|
||||||
pathSegments,
|
pathSegments,
|
||||||
testInfo.snapshotPath,
|
testInfo.snapshotPath,
|
||||||
testInfo.outputPath,
|
testInfo.outputPath,
|
||||||
testInfo.retry < testInfo.project.retries ? 'none' : testInfo.config.updateSnapshots,
|
updateSnapshots,
|
||||||
withNegateComparison,
|
withNegateComparison,
|
||||||
options
|
options
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -655,6 +655,28 @@ test('should fail with missing expectations and retries', async ({ runInlineTest
|
||||||
expect(data.toString()).toBe('Hello world');
|
expect(data.toString()).toBe('Hello world');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should update expectations with retries', async ({ runInlineTest }, testInfo) => {
|
||||||
|
const result = await runInlineTest({
|
||||||
|
...files,
|
||||||
|
'playwright.config.ts': `
|
||||||
|
module.exports = { retries: 1 };
|
||||||
|
`,
|
||||||
|
'a.spec.js': `
|
||||||
|
const { test } = require('./helper');
|
||||||
|
test('is a test', ({}) => {
|
||||||
|
expect('Hello world').toMatchSnapshot('snapshot.txt');
|
||||||
|
});
|
||||||
|
`
|
||||||
|
}, { 'update-snapshots': true });
|
||||||
|
|
||||||
|
expect(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`);
|
||||||
|
const data = fs.readFileSync(snapshotOutputPath);
|
||||||
|
expect(data.toString()).toBe('Hello world');
|
||||||
|
});
|
||||||
|
|
||||||
test('should allow comparing text with text without file extension', async ({ runInlineTest }) => {
|
test('should allow comparing text with text without file extension', async ({ runInlineTest }) => {
|
||||||
const result = await runInlineTest({
|
const result = await runInlineTest({
|
||||||
...files,
|
...files,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue