cypress-image-snapshot icon indicating copy to clipboard operation
cypress-image-snapshot copied to clipboard

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

Open nagamejun opened this issue 5 years ago • 4 comments

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

nagamejun avatar Jul 29 '20 10:07 nagamejun

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

lnbxyz avatar Aug 04 '20 13:08 lnbxyz

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

nagamejun avatar Aug 06 '20 09:08 nagamejun

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.

isaac-jordan avatar Jan 06 '21 16:01 isaac-jordan

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.

dani2112 avatar Jan 26 '21 09:01 dani2112