Jest: Stored snapshots can't be found on CI only

Created on 3 Oct 2018  ยท  6Comments  ยท  Source: facebook/jest

๐Ÿ› Bug Report

Snapshots can't be found on CI even when snapshots are checked in the source control.

  โ— Attributes
    expect(value).toMatchSnapshot()
    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.

To Reproduce

https://travis-ci.org/Prettyhtml/prettyhtml/jobs/436540742

Jest version: 23.6.0

Expected behavior

Tests should work as locally because all my snapshots are checked in the source control.

Most helpful comment

To further clarify for anyone else that stumbles on this thread, here's the situation that causes this:

 โ””โ”€ __tests__
   โ”œโ”€ foo.test.js      // <- you want to run these
   โ””โ”€ bar.test.js      // <-
 โ””โ”€ __snapshots__
   โ”œโ”€ foo.test.js.snap
   โ””โ”€ bar.test.js.snap
dist
 โ””โ”€ __tests__
   โ”œโ”€ foo.test.js      // <- CI is also running these
   โ””โ”€ bar.test.js      // <- (though they have no snapshots)

To debug this, double-check your jest.config.js and make sure you've correctly configured the testPathIgnorePatterns to include /dist/ or something similar.

Hope this helps!

All 6 comments

The issue could be identified. The test pattern matched the tests inside the production build and in the test directory :smile:

Is this something jest could have detected and warned about?

I don't think so because the directory structure isn't fixed. We could print a warning when someone is trying to run snapshot tests in a directory like dist, build which won't usually contain fixtures.

Any news as a correction?

@joaoeudes7 Look at my last comment it was my fault.

To further clarify for anyone else that stumbles on this thread, here's the situation that causes this:

 โ””โ”€ __tests__
   โ”œโ”€ foo.test.js      // <- you want to run these
   โ””โ”€ bar.test.js      // <-
 โ””โ”€ __snapshots__
   โ”œโ”€ foo.test.js.snap
   โ””โ”€ bar.test.js.snap
dist
 โ””โ”€ __tests__
   โ”œโ”€ foo.test.js      // <- CI is also running these
   โ””โ”€ bar.test.js      // <- (though they have no snapshots)

To debug this, double-check your jest.config.js and make sure you've correctly configured the testPathIgnorePatterns to include /dist/ or something similar.

Hope this helps!

Was this page helpful?
0 / 5 - 0 ratings