-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Separate snapshots into the folders close to each story #887
Comments
I think it would be best if we could make Jest consider the story tests as coming from the story file as opposed to the Does anyone know of a way to alter the location that Jest considers a test as coming from? |
Well I just looked through the source code and there is a private, but accessible API you could abuse: e.g. const thisTestPath = expect.getState("testPath")
expect.setState("testPath", "path/to/story")
runStoryshotForFile("path/to/story")
expect.setState("testPath", thisTestPath) /cc @cpojer |
@orta have you tried messing with that? I gave it a go but it didn't seem to affect things. Reading the source code a bit, it seems like reading the snapshots is done per-test-file at startup time: https://github.com/facebook/jest/blob/9b157c3a7c325c3971b2aabbe4c8ab4ce0b0c56d/packages/jest-jasmine2/src/setup-jest-globals.js#L145 This implies to me that "fooling" jest into thinking a single test file (like so: https://github.com/storybooks/storybook/blob/master/examples/test-cra/src/storyshots.test.js) is providing snapshots for multiple test files isn't really going to work. I could be wrong though. Maybe a better way forward is rather than storyshots reading all the stories in, and then looping over the stories, setting up a test for each story, it could instead hook into the I've no idea if the above would work, I'm just noting it down as something to investigate to help with this issue. |
I think you're onto something there @tmeasday. You could use jest mocking to facade storybook's |
Yeah, that's my thinking. Pretty much the exact opposite to what https://www.npmjs.com/package/jest-storybook-facade does. |
Would be a real big improvement for storyshots if you ask me! |
Hey, I've created an experimental jest matcher that will probably help here.. Will try to have a working demo with storyshots soon. |
Wow cool! @igor-dv! I was talking with @kentcdodds, this came up as well! Although there was a misconception Storyshots was outputting as 1 big snapshot (which it is NOT). It outputs all snapshots individually into 1 file. We're hoping to find a way to store the snapshots near the sourcefiles. Looking forward to seeing your proposal @igor-dv, You're on a roll! |
Oh, that's really interesting @igor-dv! Let's give it a try!! |
By the way, we should avoid to update a gigantic file frequently using git. It's good to split the My current |
Should it be marked as merged if it's merged to the release branch ? |
Not sure. I guess so, so people know it is solved? |
Has it been released? When or how can I start to use this nice feature? 😄 |
Hi @xareelee -- we'll do a 3.3 alpha soon, you can try installing that. |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 60 days. Thanks! |
Works in |
@igor-dv Using "multiSnapshots" the package https://github.com/styled-components/jest-styled-components stopped working. I guess the problem is that the method to change the serializer changed as the result snapshot is missing all the styles. They add the serializer in addition to the styleRule matcher like this
Would be nice to be compatible to that package using |
@sashless , can you please try adding this serializer to 'jest-specifics-snapshot' directly ? import { addSerializer } from 'jest-specifics-snapshot';
addSerializer(styleSheetSerializer); ( |
Yes! This fixed my serializer issue @igor-dv The package is |
@greggb , cool ! |
@igor-dv I replaced the line |
@sashless , do you have a public repo to reproduce the problem? |
I created a repo to show the problem https://github.com/sashless/storyshot-styled-components-with-multisnapshots-broken @igor-dv |
You didn't really add custom serializer in your example. Here is how it should look like. import initStoryshots, { multiSnapshotWithOptions } from '@storybook/addon-storyshots';
import styleSheetSerializer from 'jest-styled-components/src/styleSheetSerializer';
import { addSerializer } from 'jest-specific-snapshot'
addSerializer(styleSheetSerializer);
initStoryshots({
suite: 'FileProperties',
test: multiSnapshotWithOptions({}),
});
|
awesome, thanks @igor-dv |
I'm a little late to the party, @igor-dv; sorry for the slow response. My preference is for more control, but I'm willing to try without |
We really like that feature. But is it possible to use it for visual snapshots (storyshots-puppeteer) as well? So far I couldn't find anything in the docs |
Visual snapshots in storyshots are already saving separated images. |
Right now, all the screenshots are saved in only one folder Currently:
But we like to have a
|
You can possibly use this to customize the options passed to |
Ah yes, thank you! Works perfectly 👍 |
Separate snapshots into the folders close to each story storybookjs/storybook#887
以下のように、Snapshots ファイルを分割すると、`-u` でアップデートできなくなるため修正。 また、jest-styled-components も上手く機能しない。 storybookjs/storybook#887 以下の issue が参考になりそう。一旦保留とする。 storybookjs/storybook#3483
コンポーネントのストーリごとにファイルを __snapshots__ フォルダを作成するように修正 storybookjs/storybook#3483 storybookjs/storybook#887
Thanks!!! Your solution helped me a lot. Here comes another problem. Storyshots does not re-run after stories update anymore. It seems to be solved before in #2936 (comment) |
Issue by xareelee
Wednesday Mar 15, 2017 at 08:06 GMT
Originally opened as storybook-eol/storyshots#84
Currently, the
.snap
files generated by storyshots will be put in the__snapshots__
folder where theStoryshots.test.js
is.This results in a huge
.snap
file with thousands lines of code. It's hard for code review.I think that the snapshots should be put in the
__snapshots__
folder being close to the related.stories
.This will make code review easier. It's easy to know a change from which
.stories.js
file.It would be better when we need to move the whole component folder into a separated module or project without losing its snapshots, doesn't it?
The text was updated successfully, but these errors were encountered: