1

I am using jest snapshots, as well as jest-image-snapshots. They work locally, but when I run them in the azure pipeline I get:

    New snapshot was not written. The update flag must be explicitly passed to write a new snapshot.

    This is likely because this test is run in a continuous integration (CI) environment in which snapshots are not written by default.

Wouldn't updating the snapshots on every run defeat the purpose?

I've researched a bit but the best solutions I came to were updating snapshots, or removing CI=true. Removing CI=true did not work, and I don't see how updating snapshots could be a good solution.

This is happening for both unit tests, as well as image-snapshots within integration tests.

Any clarification or alternative solutions are appreciated.

skyboyer
  • 22,209
  • 7
  • 57
  • 64
Sean
  • 153
  • 1
  • 11
  • Hi Sean, is there any update for this issue? Feel free to let me know whether my anwser helps. – Jane Ma-MSFT Sep 14 '20 at 01:05
  • Thank you for the assistance Jane,. There was a ci=true in the pipeline that I had missed, which was causing issue. – Sean Sep 17 '20 at 20:05

1 Answers1

1

In a CI system, such as Azure DevOps, Jests snapshots will not be written automatically unless pass --updateSnapshot explicitly to tell it to regenerate snapshots.

To resolve this, you can run the following script:

jest --updateSnapshot

What's more, it is recommended to put snapshots in the repository rather than regenerate them in CI.

If there are no special requirements, you can firstly run snappshots locally and put the .snap files to the repository, then run on CI.

Jane Ma-MSFT
  • 4,461
  • 1
  • 6
  • 12
  • This explanation makes sense, but I don't know how to point the test script to those existing `.snap` files in the repo. I'm using CRA and running `react-scripts test --watchAll=false -u`. I would like the CI environment (CodeBuild) to read from those `.snap` files, rather than just update the snapshots, which defeats the purpose, as mentioned above. – Farid Feb 11 '21 at 04:25