igor-dv / jest-specific-snapshot

Jest matcher for multiple snapshot files per test
MIT License
56 stars 15 forks source link

Obsolete snapshots not detected #50

Open askoufis opened 1 year ago

askoufis commented 1 year ago

Obsolete snapshots are snapshots that were created by a test that no longer exists/had its name changed. These snapshots are not detected when running jest. This doesn't matter that much when running jest normally, they'll be removed the next time you update snapshots. However, when running on CI, it's often desirable to fail CI if there are obsolete snapshots. This is the behaviour that jest --ci does.

I believe these are referred to as unchecked snapshots within the jest source code. These are tracked in the snapshotState, so potentially adding them to the commonSnapshotState could fix the issue. I tried to do this but was unsuccessful.

Reproduction

  1. Create a file with 2 specific snapshots that write to the same file
  2. Run jest to create the snapshots
  3. Delete one of the snapshot tests
  4. Run jest --ci
  5. jest --ci should fail as there is an obsolete snapshot, but it passes and doesn't show any messaging about the obsolete snapshot
igor-dv commented 1 year ago

Yeah, that's actually a known issue.. I wander why I didn't mention it in the readme 🤔 . The way it was worked-around in Storybook is to create an integrity test that will check abandoned files. you can take a look here https://github.com/storybookjs/storybook/blob/next/code/addons/storyshots-core/src/api/integrityTestTemplate.ts (this code was already changed many times from the last time I'have seen, so not sure what's going on there now =) )

I will try to find some time to test your direction. can't have an ETA though