-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Add renderer option to storyshots #2414
Add renderer option to storyshots #2414
Conversation
Codecov Report
@@ Coverage Diff @@
## release/3.3 #2414 +/- ##
===============================================
+ Coverage 18.72% 18.77% +0.05%
===============================================
Files 348 348
Lines 8198 8202 +4
Branches 906 917 +11
===============================================
+ Hits 1535 1540 +5
+ Misses 5995 5932 -63
- Partials 668 730 +62
Continue to review full report at Codecov.
|
@@ -1,5 +1,5 @@ | |||
{ | |||
"presets": ["env", "react"], | |||
"presets": ["env", "stage-0", "react"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it needed? Can we include the particular transform instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the destructuring assignment here: https://github.com/storybooks/storybook/pull/2414/files#diff-75fdf0f2c6757366489b97c6898ea585R6
i would have used stage-2, but storybook itself pulls in stage-0, so i went with that to stay consistent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see. I wonder if we can remove this nested .babelrc
to avoid confusion
@ndelangen what do you think?
Looks great! Let's use this feature for storyshots of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i've extended the demo project to use it. i went for jest configuration in package.json over initializing everything in the initSnapshot file, since that is the cleaner way to do it imo
@@ -1,5 +1,5 @@ | |||
{ | |||
"presets": ["env", "react"], | |||
"presets": ["env", "stage-0", "react"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the destructuring assignment here: https://github.com/storybooks/storybook/pull/2414/files#diff-75fdf0f2c6757366489b97c6898ea585R6
i would have used stage-2, but storybook itself pulls in stage-0, so i went with that to stay consistent
import Enzyme from 'enzyme'; | ||
import Adapter from 'enzyme-adapter-react-16'; | ||
|
||
Enzyme.configure({ adapter: new Adapter() }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have this setup on root level, no need to duplicate it here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as #2414 (comment)
@@ -39,6 +39,9 @@ | |||
"@storybook/components": "^3.3.0-alpha.4", | |||
"@storybook/react": "^3.3.0-alpha.4", | |||
"babel-jest": "^21.2.0", | |||
"enzyme": "^3.2.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to have a single enzyme instance across the codebase, so it shouldn’t be added to package dependencies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i know. but i figured an "example project" should include the necessary dependencies? its a lot more difficult to understand if i need to look outside of the project for its code to work. thats why i included enzyme setup there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, makes sense
test: multiSnapshotWithOptions({ | ||
createNodeMock, | ||
}), | ||
renderer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we support custom renderers for multisnapshots as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah sure. done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it still stores all the snapshots in one file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it does. i'm currently debugging it. looks like it did not work in the first place. the multisnapshot function doesnt seem to be called correctly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should work now. we cant use enzymes mount
since that renders out the context prop (includes the file path, which is different on every machine). We also need to pass a serializer since jest-specific-snapshots doesnt use the projects serializer
mount includes context props, which means current file paths will be printed to snapshots. those are machine-dependant and differ on every enviroment. we dont want that.
onClick={[Function]} | ||
style={Object {}} | ||
> | ||
<button> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have an idea why Enzyme strips attributes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its the renderer specified in the tests. you have shallow
which shallowrenders, mount
which more or less renders the entire vdom, and render
(uses cheerio under the hood) which just prints out html. see https://github.com/airbnb/enzyme/blob/master/docs/api/render.md
like i said, we cant use mount
with multisnapshot because the snapshots then include the context
prop, and part of that is the file path. and the file path changes depending on what the absolute path on the system the snapshot is stored at is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im not very familiar with the internals of jest-specific-snapshots, but if there was a way for it to pass a relative path in the context, that would eliminate the problem. its where i see the solution to the problem at least.
i wouldnt want to modify the output of the renderer (like replacing the filepath with an empty string or somesuch), which is the only alternative i can think of
Issue: #2408
What I did
Added two options to the options passed to
initStoryshots
,renderer
andserializer
. Their usage is documented in the readme, but in short, you can pass custom renderer and serializer functions to the storyshot addon.This is probably a bit easier to use than the
test
option, which requires you to pass an entire snapshotting test.How to test
In addition to the storyshot tests currently in the addon, i added one where enzymes
mount
renderer and the serializer fromenzyme-to-json
are passed.Does this need a new example in the kitchen sink apps?
No
Does this need an update to the documentation?
Yes, which has been added.