-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
toMatchFileSnapshot does not detect obsolete snapshots #5094
Comments
Hey, thanks for raising an issue (or could it be a feature request?) I'm not familiar with general storybook/storyshots practice, so can you clarify how you were setting up separate storyshots on Jest? Storybook's documentation seems to suggest using https://github.com/igor-dv/jest-specific-snapshot, but from a quick look, it doesn't support cleaning up old snapshots either? It looks like Jest team also had this concern and that's the reason Jest doesn't have this feature builtin jestjs/jest#4231 (comment), jestjs/jest#2676 (comment) (Digging further, similar feature requests are still tracked in jestjs/jest#12734 and jestjs/jest#6383) |
Hi! Thanks for taking a look! It seems that Storybook had implemented its own This seems to be missing from the new Vitest integration (or at least I can't find it) so I implemented this myself! |
I see, so storybook is deprecating
From Vitest perspective, I don't think it's possible to make general use case of Btw, in their guide https://storybook.js.org/docs/writing-tests/storyshots-migration-guide, they say they want feedback about migration, so maybe it might worth raising a issue on their repo as well? |
From my understanding, it is impossible to track custom-named snapshots, so we cannot remove obsolete ones since they are not referenced anywhere anymore. I would recommend using a |
Describe the bug
I'm switching over from Jest to Vitest and we are using Storybook snapshots. They have an excellent guide on how to add snapshot testing using vitest - https://storybook.js.org/docs/writing-tests/storyshots-migration-guide#vitest
Since I have ~630 snapshots, I want them to be in separate files (Even for the same component) named like
MyComponent.stories.tsx
has 2 storiesError
andLoading
which would generate the following storyshotsMyComponent.Error.storyshot
MyComponent.Loading.storyshot
MagicInput.stories.tsx
has 2 storiesInvalid
andValid
which would generate the following storyshotsMagicInput.Invalid.storyshot
MagicInput.Valid.storyshot
These
*.stories.tsx
files are gathered bystorybook.test.tsx
and made into storyshots.If new stories appear, new storyshot files are generated successfully via
but if some stories are
then the useless / obsolete storyshot files are not being detected & reported or removed
While the above is a description of a very specific usecase, imagine the following (Also available as a reproduction)
If I comment out my last 2 tests, the
generic snapshot
is removed fromsuite.test.ts.snap
whilelalala-2.storyshot
is NOT removed and snapshot file still existsReproduction
https://stackblitz.com/edit/vitest-dev-vitest-opw4bq?file=test%2Fsuite.test.ts
System Info
Used Package Manager
yarn
Validations
The text was updated successfully, but these errors were encountered: