1
0
Fork 0
mirror of https://github.com/datashard/snapshot.git synced 2025-05-17 04:37:21 +00:00

remove unnecessary console logs and add ENV var check

This commit is contained in:
Joshua 2023-03-23 16:44:25 +01:00
parent 76c14b02c6
commit 7645db2fda

View file

@ -41,7 +41,7 @@ const store_snapshot = (store, props = { value, name, path, raiser }) => {
const expectedPath = path.join(snapshotPath, `${fileName}.json`); const expectedPath = path.join(snapshotPath, `${fileName}.json`);
cy.task("readFileMaybe", expectedPath).then((exist) => { cy.task("readFileMaybe", expectedPath).then((exist) => {
if (exist) { if (exist && !Cypress.env().SNAPSHOT_UPDATE) {
props.raiser({ value: props.value, expected: JSON.parse(exist) }); props.raiser({ value: props.value, expected: JSON.parse(exist) });
} else { } else {
cy.writeFile(expectedPath, JSON.stringify(props.value)); cy.writeFile(expectedPath, JSON.stringify(props.value));
@ -56,7 +56,6 @@ const set_snapshot = (
if (!store) return; if (!store) return;
const message = Cypress._.last(snapshotName); const message = Cypress._.last(snapshotName);
console.log("Current Snapshot name", snapshotName);
const devToolsLog = { $el: serialized }; const devToolsLog = { $el: serialized };
@ -74,16 +73,18 @@ const set_snapshot = (
const raiser = ({ value, expected }) => { const raiser = ({ value, expected }) => {
const result = compareValues({ expected, value }); const result = compareValues({ expected, value });
result.orElse((json) => { if (!Cypress.env().SNAPSHOT_UPDATE && result.value) {
devToolsLog.message = json.message; result.orElse((json) => {
devToolsLog.expected = expected; devToolsLog.message = json.message;
delete devToolsLog.value; devToolsLog.expected = expected;
devToolsLog.value = value; delete devToolsLog.value;
devToolsLog.value = value;
throw new Error( throw new Error(
`Snapshot Difference. To update, delete snapshot file and rerun test.\n${json.message}` `Snapshot Difference.\nPlease Update the Snapshot\n\n\t${json.message}`
); );
}); });
}
}; };
Cypress.log(options); Cypress.log(options);
@ -95,9 +96,8 @@ const set_snapshot = (
}); });
}; };
const get_test_name = (test) => test.titlePath;
const get_snapshot_name = (test, custom_name) => { const get_snapshot_name = (test, custom_name) => {
const names = get_test_name(test); const names = test.titlePath;
const index = custom_name; const index = custom_name;
names.push(String(index)); names.push(String(index));
@ -110,7 +110,6 @@ module.exports = (value, step, options) => {
if (typeof step === "object") options = step; if (typeof step === "object") options = step;
if (typeof value !== "object" || Array.isArray(value)) if (typeof value !== "object" || Array.isArray(value))
value = { data: value }; value = { data: value };
console.log("value", value);
const name = get_snapshot_name( const name = get_snapshot_name(
Cypress.currentTest, Cypress.currentTest,
@ -120,7 +119,6 @@ module.exports = (value, step, options) => {
const serialized = serializer(value); const serialized = serializer(value);
const store = newStore(serialized || {}); const store = newStore(serialized || {});
console.log({ step, options });
set_snapshot(store, { set_snapshot(store, {
snapshotName: name, snapshotName: name,
snapshotPath: options.snapshotPath, snapshotPath: options.snapshotPath,