question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Interactive Snapshot Mode not working when snapshotName specified

See original GitHub issue

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…

🐛 Bug Report

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.

To Reproduce

  1. Create a test file with this content :
// 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');
  });
});
  1. run $ yarn --watch my.test.js
  2. tests pass, snapshot are written for the first time
  3. modify all asserted objects (you can just copy/paste following code):
// 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');
  });
});
  1. tests break, hit i key to enter Interactive Snapshot Mode
  2. hit u key to update first failing snapshot
  3. hit u key to update last failing snapshot
  4. snapshot successfully updated :
Interactive Snapshot Result
 › 2 snapshots reviewed, 2 snapshots updated
  1. hit enter key to end Interactive Snapshot Mode
  2. shell goes back to first failing snapshot because Jest didn’t actually updated snapshot on filesystem
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.

Expected behavior

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.
  • If you remove snapshot names snapshot 1 and snapshot 2 and go through the same steps above, Jest will behave correctly at step 10.
  • it seems to work if the test file my.test.js contains only one test block :
describe('those tests', () => {
  test('will fail', () => {
    expect({ a: 52 }).toMatchSnapshot({
      a: 52
    }, 'snaphot 1');
  });
});

Link to repl or repo (highly encouraged)

https://github.com/mr-wildcard/jest-snapshot-interactive-mode

Run npx envinfo --preset jest

System:
    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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rickhanloniicommented, Oct 17, 2018

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!

1reaction
mr-wildcardcommented, Sep 25, 2018

I added a repo for reproduction steps 😉 (https://github.com/mr-wildcard/jest-snapshot-interactive-mode)

Read more comments on GitHub >

github_iconTop Results From Across the Web

no interaction in interactive snapshot mode - Stack Overflow
I use jest 23.2.0 for my current project. If I run jest --watchAll some snapshot tests fail. I press i to go to...
Read more >
SVMDR failed to create Snapshot copy due to error sourceVol ...
Issue. A specific volume or set of volumes involved in an SVMDR relationship fails with the following error.
Read more >
Overview of ZFS Snapshots (Solaris ZFS Administration Guide)
Snapshots are created by using the zfs snapshot command, which takes as its only argument the name of the snapshot to create. The...
Read more >
HPE Recovery Manager Central 6.3.x CLI Reference Guide
With RMC-S, the command only supports the online backup of an entire SQL database ... If not specified, RMC-S creates the snapshot using...
Read more >
h13697-dell-emc-powermax-vmax-all-flash-timefinder-snapvx ...
TimeFinder legacy modes: Mirror, Clone, and VP Snap . ... storage array and are not specific to snapshots. The following are explanations of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found