mirror of
https://github.com/datashard/snapshot.git
synced 2024-12-03 10:27:35 +00:00
chore: commit
This commit is contained in:
parent
1fe4562b9f
commit
ce42d28dd1
5 changed files with 48 additions and 28 deletions
|
@ -43,5 +43,15 @@ describe("@datashard/snapshot", () => {
|
|||
snapshotName: "Complex"
|
||||
})
|
||||
})
|
||||
it('random test string',{
|
||||
env: {
|
||||
SNAPSHOT_UPDATE: true,
|
||||
},
|
||||
}, () => {
|
||||
cy.wrap([1, 2, 3, 4]).snapshot({
|
||||
snapshotPath: 'cypress/snapshots',
|
||||
snapshotName: "rndmtst"
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
{
|
||||
"status": 200,
|
||||
"response": {
|
||||
"array": [0, 1, 2, "Three"],
|
||||
"array": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
"Three"
|
||||
],
|
||||
"object": {
|
||||
"with": "more details"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -45,7 +45,6 @@ function containsDiffChars(str) {
|
|||
|
||||
const compare = (expected, value) => {
|
||||
let compareResult = "";
|
||||
let compareSuccess = true;
|
||||
|
||||
if (isNestedData(expected, value)) {
|
||||
if (Array.isArray(expected)) {
|
||||
|
@ -62,7 +61,6 @@ const compare = (expected, value) => {
|
|||
|
||||
dataX.forEach(function (item, index) {
|
||||
const resultset = compare(item, dataY[index]);
|
||||
compareSuccess = resultset.success;
|
||||
compareResult += resultset.result;
|
||||
});
|
||||
compareResult += `],`;
|
||||
|
@ -79,14 +77,11 @@ const compare = (expected, value) => {
|
|||
|
||||
Object.keys(dataX).forEach((key) => {
|
||||
const resultset = compare(dataX[key], dataY[key]);
|
||||
|
||||
compareSuccess = resultset.success;
|
||||
compareResult += `"${key}": ${resultset.result}`;
|
||||
});
|
||||
compareResult += `}`;
|
||||
}
|
||||
} else {
|
||||
compareSuccess = false;
|
||||
compareResult = checkDataState(expected, value);
|
||||
}
|
||||
let result = parseTextToJSON(compareResult);
|
||||
|
|
|
@ -16,20 +16,40 @@ const newStore = (name) => {
|
|||
return initStore(name);
|
||||
};
|
||||
|
||||
const writeSnapshot = (path, value) => {
|
||||
return cy.writeFile(path, JSON.stringify(value, null, 2));
|
||||
}
|
||||
|
||||
const store_snapshot = (store, props = { value, name, path, raiser }) => {
|
||||
const err = {
|
||||
mes: null
|
||||
}
|
||||
const expectedPath = path.join(
|
||||
props.path ||
|
||||
Cypress.config("snapshot").snapshotPath ||
|
||||
"cypress/snapshots",
|
||||
Cypress.config("snapshot").snapshotPath ||
|
||||
"cypress/snapshots",
|
||||
`${props.name.join("_").replace(/ /gi, "-").replace(/\//gi, "-")}.json`
|
||||
);
|
||||
cy.task("readFileMaybe", expectedPath).then((exist) => {
|
||||
if (exist && !Cypress.env().SNAPSHOT_UPDATE) {
|
||||
props.raiser({ value: props.value, expected: JSON.parse(exist) });
|
||||
} else {
|
||||
cy.writeFile(expectedPath, JSON.stringify(props.value, null, 2));
|
||||
}
|
||||
});
|
||||
|
||||
// cy.on('fail', (error, runnable) => {
|
||||
// if (error.message.includes('failed because the file does not exist at the following path')) {
|
||||
// err.mes = 'didNotExist'
|
||||
// }
|
||||
// writeSnapshot(expectedPath, props.value)
|
||||
// })
|
||||
|
||||
try {
|
||||
cy.readFile(expectedPath).then((file) => {
|
||||
if (file && !Cypress.env().SNAPSHOT_UPDATE) {
|
||||
props.raiser({ value: props.value, expected: file });
|
||||
} else {
|
||||
writeSnapshot(expectedPath, props.value)
|
||||
}
|
||||
})
|
||||
|
||||
} catch (error) {
|
||||
writeSnapshot(expectedPath, props.value)
|
||||
}
|
||||
};
|
||||
|
||||
const set_snapshot = (
|
||||
|
@ -63,10 +83,6 @@ const set_snapshot = (
|
|||
value,
|
||||
};
|
||||
|
||||
// ╺
|
||||
// ┿
|
||||
// ╳
|
||||
|
||||
throw new Error(
|
||||
`Snapshot Difference found.\nPlease Update the Snapshot\n\n${JSON.stringify(
|
||||
JSON.parse(result.result),
|
||||
|
|
|
@ -1,9 +1,3 @@
|
|||
const fs = require("fs");
|
||||
|
||||
module.exports = (filename) => {
|
||||
if (fs.existsSync(filename)) {
|
||||
return fs.readFileSync(filename, "utf8");
|
||||
}
|
||||
|
||||
return false;
|
||||
module.exports = () => {
|
||||
return console.log("This file is not needed anymore, you can take the .tasks() function out of your Configs")
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue