Sorry for the long issue, but I tried to give as much insights as possible as this issue was hard to spot at first and kind of hard to repro..
Interactive Snapshot Mode runs endlessly if multiple snapshots with snapshotName in a test file break.
Even if I update the failing snapshots, the interactive shell goes back to the same diff error with this error printed :
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.
// my.test.js
describe('those tests', () => {
test('will fail', () => {
expect({ a: 2 }).toMatchSnapshot({
a: 2
}, 'snaphot 1');
});
test('will also fail', () => {
expect({ a: 1 }).toMatchSnapshot({
a: 1
}, 'snapshot 2');
});
});
$ yarn --watch my.test.js// my.test.js
describe('those tests', () => {
test('will fail', () => {
expect({ a: 5 }).toMatchSnapshot({
a: 5
}, 'snaphot 1');
});
test('will also fail', () => {
expect({ a: 4 }).toMatchSnapshot({
a: 4
}, 'snapshot 2');
});
});
i key to enter Interactive Snapshot Modeu key to update first failing snapshotu key to update last failing snapshotInteractive Snapshot Result
› 2 snapshots reviewed, 2 snapshots updated
enter key to end Interactive Snapshot ModeNew 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.
At step 10, Jest should print a success message saying that all snapshots have been written.
// expected output
PASS 05_jest-snapshot/__tests__/my.test.js
those tests
✓ will fail (1ms)
✓ will also fail (1ms)
› 1 snapshot written.
Snapshot Summary
› 1 snapshot written from 1 test suite.
Test Suites: 1 passed, 1 total
Tests: 2 passed, 2 total
Snapshots: 1 written, 1 passed, 2 total
Time: 0.11s, estimated 1s
Ran all test suites related to changed files.
snapshot 1 and snapshot 2 and go through the same steps above, Jest will behave correctly at step 10.my.test.js contains only one test block : describe('those tests', () => {
test('will fail', () => {
expect({ a: 52 }).toMatchSnapshot({
a: 52
}, 'snaphot 1');
});
});
https://github.com/mr-wildcard/jest-snapshot-interactive-mode
npx envinfo --preset jestSystem:
OS: macOS High Sierra 10.13.6
CPU: x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
Binaries:
Node: 8.11.3 - ~/.nvm/versions/node/v8.11.3/bin/node
Yarn: 1.9.4 - /usr/local/bin/yarn
npm: 5.6.0 - ~/.nvm/versions/node/v8.11.3/bin/npm
npmPackages:
jest: ^23.6.0 => 23.6.0
Couldn't provide a repl because of interactive mode.
A repo would be awesome, although your reproduction steps looks good!
@rickhanlonii mind taking a look?
I added a repo for reproduction steps ;) (https://github.com/mr-wildcard/jest-snapshot-interactive-mode)
Wow, really great reproduction steps @mr-wildcard, I'll take a look!
Looked into this and found that this is related to this issue: https://github.com/facebook/jest/issues/7197
I confirmed that the root cause of this is #7197 so going to close in favor of that
Thanks again for the report @mr-wildcard!