cypress-image-snapshot
cypress-image-snapshot copied to clipboard
How can I stop updating UI snapshots with Cypress e2e snapshot testing ?
I'm running cypress e2e testing and ui snapshotting with cypress-image-snapshot on a web app. Whenever matchImageSnapshot() succeeds, it replaces the existing .png image with a newer one.
I run the following:
cypress run --env updateSnapshots=false
a) Even with updateSnapshots set false, images are still updating. Any ideas? b) Updating an image with a newer identical image seems unnecessary. Is this the intended behavior?
Running with:
Mac OS 10.15.5
Cypress 4.11.0
cypress-image-snapshot ^3.1.1
Similar to this question https://stackoverflow.com/questions/59277412/how-to-stop-updating-ui-snapshots-with-cypress-e2e-snapshot-testing-and-vue
Try setting env.updateSnapshots to false in your cypress.json.
Thank you for your answer. I tried it but it didn't work.
Ensure you aren't deleting your snapshots folder automatically by accident. I had a pre-cypress hook that was cleaning up the snapshots folder, thus the next time my test ran there was nothing to compare against, so it just created the files again.
From looking at the source code cypress-image-snapshot seems to do the following:
- Copy the existing snapshot file to a temporary file
- Match with new screenshot
- Update the temporary snapshot file with the new screenshot if requested
- Copy the temporary snapshot file to the original snapshot location regardless if the snapshot file was updated
This means that actually the snapshot most likely is not updated but the file will still be overwritten with its original content.