working code

This commit is contained in:
Joshua 2024-03-28 10:44:10 +01:00
parent d45d7479f0
commit 930662045c
4 changed files with 14 additions and 4 deletions

View file

@ -28,7 +28,7 @@ This will register a new Command `.snapshot()`, to create new Snapshots and once
## Config ## Config
You can pass `updateSnapshots` and `useFolders` as options in the `cypress.config.js` file You can pass `updateSnapshots` and `useFolders` as options in the `cypress.config.js` file
<!-- ![Example Settings for the Module](./.github/assets/config.png) --> ![Example Settings for the Module](./.github/assets/config.png)
Alternatively, you can also add `snapshotUpdate` as an Environment Variable to update your snapshots. Alternatively, you can also add `snapshotUpdate` as an Environment Variable to update your snapshots.
@ -75,4 +75,5 @@ If a step wasn't named, it will instead use the `<It>`for the file name, though
Of course, if a value changed, it will no longer match the snapshot and throw an Error. Of course, if a value changed, it will no longer match the snapshot and throw an Error.
![](./.github/assets/Error.png) ![](./.github/assets/Error.png)

View file

@ -1,7 +1,7 @@
const { defineConfig } = require("cypress"); const { defineConfig } = require("cypress");
module.exports = defineConfig({ module.exports = defineConfig({
fixturesFolder: "cypress/fixtures",
snapshot: { snapshot: {
// updateSnapshots: true, // updateSnapshots: true,
useFolders: true, useFolders: true,

View file

@ -22,9 +22,10 @@ const parseTextToJSON = (text) => text.replace(/\| [✅➖➕⭕]/g, "").trim().
const store_snapshot = (props = { value, name, raiser }) => { const store_snapshot = (props = { value, name, raiser }) => {
if (Cypress.env().updateSnapshots || Cypress.config('snapshot').updateSnapshots) { if (Cypress.env().updateSnapshots || Cypress.config('snapshot').updateSnapshots) {
cy.SNAPSHOT_prettyprint({ title: "INFO", type: "info", message: "Saving Snapshot" }) cy.SNAPSHOT_prettyprint({ title: "INFO", type: "info", message: "Saving Snapshot" })
cy.writeFile(`${props.name}.json`, JSON.stringify(props.value, null, 2)) cy.writeFile(`${Cypress.env().fixturesFolder}/${props.name}.json`, JSON.stringify(props.value, null, 2))
} else { } else {
// TODO: Figure out how to replace the fixture folder name if people move it // TODO: Figure out how to replace the fixture folder name if people move it
// const fixtureName = props.name.replace(Cypress.env().fixturesFolder, "")
const fixtureName = props.name.replace("cypress/fixtures", "") const fixtureName = props.name.replace("cypress/fixtures", "")
cy.fixture(fixtureName).then(content => props.raiser({ value: props.value, expected: content })) cy.fixture(fixtureName).then(content => props.raiser({ value: props.value, expected: content }))
} }

View file

@ -0,0 +1,8 @@
{
"data": [
1,
2,
3,
4
]
}