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

Make it possible to save snapshots next to each story #19128

Closed
Robin-Hoodie opened this issue Sep 7, 2022 · 2 comments
Closed

Make it possible to save snapshots next to each story #19128

Robin-Hoodie opened this issue Sep 7, 2022 · 2 comments

Comments

@Robin-Hoodie
Copy link

Is your feature request related to a problem? Please describe

Currently, the setup instructions read as follows:

Create a new test file with the name Storyshots.test.js. (Or whatever the name you prefer, as long as it matches Jest's config testMatch). Then add following content to it:

import initStoryshots from '@storybook/addon-storyshots';

initStoryshots();

That's all.
Now run your Jest test command. (Usually, npm test.) Then you can see all of your stories are converted as Jest snapshot tests.

There are 2 problems I've noticed with this:

  1. All snapshots are written to a __snapshots__/Storyshots.test.js.snap file. This can become a nightmare to review pretty quickly
  2. As the Storyshots.test.js file is an arbitrary test file, it's not picked up by Jest if running a specific (set of) test file(s). E.g. running jest foo.test.js will not check any snapshots for foo.stories.js

I know this has been brought up in #3917 & #887 which both seem to be about solving problem#1 but neither of these solve problem#2

Describe the solution you'd like

I assume it's possible to spend a few hours/days to configure your way around this, but to me this seems like it should be a logical default. The current default setup requires quite some googling & manual configuration to solve problem#1 & does not solve problem#2

@thedamon
Copy link

thedamon commented Oct 3, 2022

I believe it was the default previously. We recently updated storybook from 5 to 6 and our snapshot location changed.

I thought I liked the new behaviour as it allowed us to review code changes and storyshot changes separately when multiple files were updated, but.. the default behaviour seems to be dumping them all according to path next to the file that launched the test is, which is definitely not ideal as we have other files in that directory

ie
/test/vue.snapshot.test.js
outputs all the snashots to
/test/{path to story}/__snapshots__/{name of story}.storyshot
which works out to
/test/packages/components/button/vue/stories/__snapshots__/button.vue.stories.storyshot

and is really odd.

@jonniebigodes
Copy link
Contributor

The Storyshots addon is officially deprecated and will be removed in a future release of Storybook. To help with the transition process, we've created a migration guide for the available options and common use cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants