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

Explain which snapshots are obsolete #5005

Closed
crubier opened this issue Dec 3, 2017 · 11 comments · Fixed by #5020
Closed

Explain which snapshots are obsolete #5005

crubier opened this issue Dec 3, 2017 · 11 comments · Fixed by #5020

Comments

@crubier
Copy link

crubier commented Dec 3, 2017

When jest finds obsolete snapshots, it does not explain which one they are. This can be very frustrating, when you have many snapshots and you can't find which one is wrong...

The problem was also shortly discussed in #3581

Jest output:

 › 2 obsolete snapshots found.
Snapshot Summary
 › 2 obsolete snapshots found, run with `npm run prod-test -- -u` to remove them.

Test Suites: 5 passed, 5 total
Tests:       211 passed, 211 total
Snapshots:   190 passed, 190 total
Time:        13.694s
Ran all test suites.

I expect an output more like:

 › 2 obsolete snapshots found:
   - ThisComponent
   - ThisOtherComponent

Snapshot Summary
 › 2 obsolete snapshots found, run with `npm run prod-test -- -u` to remove them.

Test Suites: 5 passed, 5 total
Tests:       211 passed, 211 total
Snapshots:   190 passed, 190 total
Time:        13.694s
Ran all test suites.

This is a problem for me because when I run tests locally, no snapshot are obsolete, but when run in my CI/CD, it finds 2 obsolete snapshots, without telling me which ones....

@crubier crubier changed the title Explain which snapshot are obsolete Explain which snapshots are obsolete Dec 3, 2017
@cpojer
Copy link
Member

cpojer commented Dec 4, 2017

Yeah, I like it. Are you willing to work on a pull request for this? :) You can look in the code for "obsolete snapshot" and it will probably point you to the right place.

@crubier
Copy link
Author

crubier commented Dec 4, 2017

Hey, I tried to solve this, but unfortunately the reporter is only given a SnapshotSummary:

export type SnapshotSummary = {
  added: number,
  didUpdate: boolean,
  failure: boolean,
  filesAdded: number,
  filesRemoved: number,
  filesUnmatched: number,
  filesUpdated: number,
  matched: number,
  total: number,
  unchecked: number,
  unmatched: number,
  updated: number,
};

This summary does not include the name of removed/obsolete snapshots, so they would need to be added higher in the chain... I don't have much time for that...

@schu34
Copy link

schu34 commented Sep 21, 2018

Man this would be great... I could try and look into it but I'd need some guidance on where the filenames could be added

@SimenB
Copy link
Member

SimenB commented Sep 22, 2018

This is fixed, isn't it? See #5020

@ndelangen
Copy link
Contributor

ndelangen commented Jul 9, 2019

May this have regressed recently?

I ran into this:
Screenshot 2019-07-09 at 11 39 59

When updating, no file on my fs would actually change; so I had no idea what was wrong. The CI kept asking me to update snapshots, but when I did, no files would change.

I found out which file jest was 'complaining' about by hacking into the TestScheduler.

The file jest considered 'obsolete' was a snapshot that got copied into my dist folder somehow.


Or is this a different usecase from the issue above?
It would have saved me quite some time tracking down which file had a problem if jest would have told me.

I also looked at the json output from jest. But the reporter only gets the count of 'deleted' files:

  "numFailedTestSuites": 0,
  "numFailedTests": 0,
  "numPassedTestSuites": 105,
  "numPassedTests": 833,
  "numPendingTestSuites": 0,
  "numPendingTests": 0,
  "numRuntimeErrorTestSuites": 0,
  "numTodoTests": 0,
  "numTotalTestSuites": 105,
  "numTotalTests": 833,
  "openHandles": [
    
  ],
  "snapshot": {
    "added": 0,
    "didUpdate": false,
    "failure": true,
    "filesAdded": 0,
    "filesRemoved": 1,
    "filesUnmatched": 0,
    "filesUpdated": 0,
    "matched": 269,
    "total": 269,
    "unchecked": 0,
    "uncheckedKeysByFile": [
      
    ],
    "unmatched": 0,
    "updated": 0
  },
  "startTime": 1562662045637,
  "success": false,

I wonder why jest considers this file "deleted".

@SimenB
Copy link
Member

SimenB commented Jul 9, 2019

Hmm, perhaps. From a cursory look at the linked PR we only check for individual snapshots within a file, but in your case a whole file is obsolete. We should probably include the filename in that case. Would you mind opening up a new issue with a reproduction? I'd guess just adding a dummy snapshot file should reproduce?

@ndelangen
Copy link
Contributor

@SimenB yes, I'd love to help out fix this, would you be able to assist me in effectively getting up to speed so i can open a PR?

@SimenB
Copy link
Member

SimenB commented Jul 9, 2019

For sure! If you can put together a small reproduction I can verify my theory (or dig some more) so I can provide proper guidance 🙂

@ndelangen
Copy link
Contributor

Thank you! We can pair on it if you'd like?

@yanlee26
Copy link

Snapshot Summary
› 1 snapshot obsolete from 1 test suite. To remove it, press u.

@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 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants