Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest -u -t deletes all other snapshot files #8375

Closed
GSynergy opened this issue Apr 24, 2019 · 4 comments
Closed

Jest -u -t deletes all other snapshot files #8375

GSynergy opened this issue Apr 24, 2019 · 4 comments

Comments

@GSynergy
Copy link

GSynergy commented Apr 24, 2019

🐛 Bug Report

Edit: Only happens when defining custom snapshot matchers such as toMatchTrimmedSnapshot from the docs.

As listed in documentation, I tried to use jest -u -t to only run and update the snapshot of a particular test. It did run and updated the snapshot for that test, however, all snapshot files for other (skipped) tests were deleted. Please see log below:

PASS tests/pattern.spec.js (7.224s)

Snapshot Summary
› 6 snapshot files removed from 6 test suites.

Test Suites: 10 skipped, 1 passed, 1 of 11 total
Tests: 72 skipped, 1 passed, 73 total
Snapshots: 6 files removed, 1 passed, 1 total
Time: 10.072s
Ran all test suites with tests matching "pattern.*".

To Reproduce

Steps to reproduce the behavior:

  1. Create two snapshot tests in two different spec files.
  2. Run all tests using jest. Check that the two tests have produced two different snapshot files
  3. Try updating the snapshot by using 'jest -u -t '
  4. Observe that the snapshots for other tests are deleted

Expected behavior

Snapshot of the test(s) matching the pattern should be updated. All other snapshots should remain intact

Link to repl or repo (highly encouraged)

https://github.com/GSynergy/Snapshot-Bug

Run npx envinfo --preset jest

Paste the results here:

npx: installed 1 in 2.324s

  System:
    OS: macOS High Sierra 10.13.6
    CPU: (4) x64 Intel(R) Core(TM) i7-6567U CPU @ 3.30GHz
  Binaries:
    Node: 9.11.2 - ~/.nvm/versions/node/v9.11.2/bin/node
    Yarn: 1.12.3 - ~/.nvm/versions/node/v9.11.2/bin/yarn
    npm: 5.6.0 - ~/.nvm/versions/node/v9.11.2/bin/npm
  npmPackages:
    jest: ^24.0.0 => 24.0.0 
@jeysal
Copy link
Contributor

jeysal commented Apr 24, 2019

This worked correctly for me when trying this with a minimal Jest setup - the snapshot in the focused test case is updated, the other one in the same snapshot file and the other one in a different snapshot file remain unchanged. Please provide a repro so we can reopen and see if other things might be involved in your case.

@jeysal jeysal closed this as completed Apr 24, 2019
@GSynergy
Copy link
Author

Thanks @jeysal for reviewing.

Found out that this is happening when expect has been extended to use toMatchSnapshot, as per documentation at https://jestjs.io/docs/en/expect#expectextendmatchers

To reproduce: https://github.com/GSynergy/Snapshot-Bug

@jeysal
Copy link
Contributor

jeysal commented Apr 25, 2019

Thanks, this reproduces for me now. I've updated the OP with the additional info.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants