jaredpalmer / cypress-image-snapshot

Catch visual regressions in Cypress
MIT License
888 stars 160 forks source link

How can I stop updating UI snapshots with Cypress e2e snapshot testing ? #140

Open nagamejun opened 4 years ago

nagamejun commented 4 years ago

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

lnbxyz commented 4 years ago

Try setting env.updateSnapshots to false in your cypress.json.

nagamejun commented 4 years ago

Thank you for your answer. I tried it but it didn't work.

isaac-jordan commented 3 years ago

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.

dani2112 commented 3 years ago

From looking at the source code cypress-image-snapshot seems to do the following:

  1. Copy the existing snapshot file to a temporary file
  2. Match with new screenshot
  3. Update the temporary snapshot file with the new screenshot if requested
  4. 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.