integrate toBeGolden with jest's snapshot system (#3124)
This commit is contained in:
parent
e5afd92762
commit
d2f24e8888
|
|
@ -120,11 +120,31 @@ class PlaywrightEnvironment extends NodeEnvironment {
|
||||||
|
|
||||||
const testOptions = this.global.testOptions;
|
const testOptions = this.global.testOptions;
|
||||||
function toBeGolden(received, goldenName) {
|
function toBeGolden(received, goldenName) {
|
||||||
return GoldenUtils.compare(received, {
|
const {snapshotState} = this;
|
||||||
|
const updateSnapshot = snapshotState._updateSnapshot;
|
||||||
|
const expectedPath = path.join(testOptions.GOLDEN_DIR, goldenName);
|
||||||
|
const fileExists = fs.existsSync(expectedPath);
|
||||||
|
if (updateSnapshot === 'all' || (updateSnapshot === 'new' && !fileExists)) {
|
||||||
|
fs.writeFileSync(expectedPath, received);
|
||||||
|
if (fileExists)
|
||||||
|
snapshotState.updated++;
|
||||||
|
else
|
||||||
|
snapshotState.added++;
|
||||||
|
return {
|
||||||
|
pass: true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const {pass, message} = GoldenUtils.compare(received, {
|
||||||
goldenPath: testOptions.GOLDEN_DIR,
|
goldenPath: testOptions.GOLDEN_DIR,
|
||||||
outputPath: testOptions.OUTPUT_DIR,
|
outputPath: testOptions.OUTPUT_DIR,
|
||||||
goldenName
|
goldenName
|
||||||
});
|
});
|
||||||
|
if (pass)
|
||||||
|
snapshotState.matched++;
|
||||||
|
else
|
||||||
|
snapshotState.unmatched++;
|
||||||
|
return {pass, message};
|
||||||
};
|
};
|
||||||
this.global.expect.extend({ toBeGolden });
|
this.global.expect.extend({ toBeGolden });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue