-
-
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
Add ability to use image snapshots to addon-storyshots #2413
Add ability to use image snapshots to addon-storyshots #2413
Conversation
just an fyi, since we added image-snapshot testing to our suites a couple of days ago: puppeteer will render text slightly different depending on the enviroment you run it on (especially mac vs linux based containers). This means you either need to provide a big enough margin of error, or you need to record your snapshots locally from inside the container. Either way, this change will mean that users who use container for their CI will need to modify those to include chrome. Definitely a breaking change here. |
@tobilen I do not understand why this is a breaking change as it just adds an option to generate image snapshots. If one is using the addon-storyshots, he must use this option to generate images and thus the concern about linux/mac is up to him to handle while doing this, isn't it ? |
e4c45dc
to
a742d00
Compare
@Hypnosphi could you give me a hint on what to do next to go on with this ? |
@Hypnosphi in the meantime, can you elaborate on why this is a breaking change ? 🤔 |
I'd like to hear from @ndelangen, he has set up visual tests for kitchen sink apps |
hey @thomasbertet i mistakenly assumed you'd want storyshots to do image snapshotting as a default. i now see that you're just providing a helper method. Sorry about that. I would include something about that in the readme though. |
</span> | ||
); | ||
|
||
storiesOf('Button - for-image-snapshot', module) |
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 you please follow the current naming convention we have?
storiesOf('Addon Storyshots.Image Snapshot 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.
I need a pattern to match to avoid generating all images.
WDYT about Addon Storyshots.Button.ImageSnapshot
where ImageSnapshot
is the pattern I'm matching ?
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.
what's wrong with matching that entire string? is it because the entire kind name isn't available to you because of the hierarchy tree?
import path from 'path'; | ||
|
||
initStoryshots({ | ||
suite: 'Image snapshots', |
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 you document all of these options and the possible inputs for these in README.md
?
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.
In fact I already documented inside the README the three params for the imageSnapshot
function. (the function that you assign to the test
param of initStoryshots.)
The "suite" option & all other initStoryshots params are already documented, nothing new from this PR.
) | ||
); | ||
|
||
storiesOf('Some really long story kind description - for-image-snapshot', module) |
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.
please nest this under the previous Addon Storyshots
section
Thanks for the contribution, I'm pretty excited for this new feature! |
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.
To be honest. I feel a bit uncomfortable with adding this feature to StoryShots. Looks like it should be a separate plugin even from the dependencies' point of view, but I am not 100% sure about it (And I was not a part of the discussion at the beginning), so I don't want to be strict and picky.
addons/storyshots/src/index.js
Outdated
@@ -16,6 +16,8 @@ export { | |||
snapshotWithOptions, | |||
shallowSnapshot, | |||
renderOnly, | |||
imageSnapshot, | |||
imageSnapshotWithOptions, |
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 think, since this is a new feature, you can provide just the imageSnapshot
method with the relevant defaults, instead of extending the API with two methods. (IMO it's already confusing enough, and we need to start thinking of some refactoring here for the breaking version)
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.
Fair enough, did it
addons/storyshots/src/test-bodies.js
Outdated
@@ -39,3 +43,63 @@ export function renderOnly({ story, context }) { | |||
const storyElement = story.render(context); | |||
reactTestRenderer.create(storyElement); | |||
} | |||
|
|||
export const imageSnapshotWithOptions = ({ port = 6006, host = 'localhost', scheme = 'http' }) => { |
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.
As I see there is no cohesion between other "bodies" in this module and the imageSnapshot
(and it's a big one). I think worth extracting it into a separate file. index.js
can just import it from 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, did it.
addons/storyshots/src/test-bodies.js
Outdated
const baseUrl = `${scheme}://${host}:${port}`; | ||
const encodedKind = encodeURIComponent(context.kind); | ||
const encodedStoryName = encodeURIComponent(context.story); | ||
const storyUrl = `/iframe.html?selectedKind=${encodedKind}&selectedStory=${encodedStoryName}`; |
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.
As I understand imageSnapshot
won't work for RN. It makes this addon a bit inconsistent. This should be documented very clearly. You can even throw some error in case someone tries to run it for RN.
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 added a message about it inside README & the test itself.
Thanks for all your feedbacks ! I think I got every one of them dealt with. Please let me know :) |
We're gonna need to fix the unit test as well. Let me see if I can install Chrome on our CircleCI instance. edit: just converted CI to use the docker image with browsers. we're gonna need to fix the test to serve storybook in the background. |
Codecov Report
@@ Coverage Diff @@
## master #2413 +/- ##
==========================================
- Coverage 34.35% 34.31% -0.05%
==========================================
Files 390 391 +1
Lines 8772 8806 +34
Branches 903 899 -4
==========================================
+ Hits 3014 3022 +8
- Misses 5145 5187 +42
+ Partials 613 597 -16
Continue to review full report at Codecov.
|
@danielduan What we did internally at my company was just to "sleep" for some time before running the test. It sounds pretty hacky but hey it works ! 🍭 Our CicleCI config is as follow:
The last command runs the test which needs the storybook to be running. Is this something we "could" imagine ? If you know a way to know when the storybook has launched, then we could possibly hook into this "event" ? |
Why running it on ci? Why not just export the static version? |
@igor-dv what do you mean ? I'm not sure I get it. |
@igor-dv the CI is for running the test to make sure this does not regress. @thomasbertet feel free to toy with the CircleCI settings on your branch to get it working. |
I think @igor-dv meant that we can run |
@Hypnosphi, exactly =) |
Is there a way to exclude a story from screenshot testing, but still include in regular snapshots? This may be needed when using transitions and animations in components |
Yes you can use the same parameters as for other storyshots config. In fact, that's what I did, I created two storyshots instances, and each instance is running their proper stories. Note that you cannot run within a single |
@Hypnosphi any hint on how to start a node server to serve the static storybook on CircleCI ? Do you have any experience in this that can save me some time ? |
1ff1ede
to
b154fc5
Compare
Is something missing here to go forward? |
This, at least |
@Hypnosphi I'm not sure I follow. I mean there is nothing to do in particular to separate visual regressions (ie. image snapshots) from markup regressions. The main issue I had was the integration with CRA, as it runs everything that follows the .test.js pattern,. At the time, I did not wanted them to be run automatically, because it requires you to build the static-storybook. This seemed to me a bit too long to be integrated as-is. That is why I had created a different approach in the CRA kitchen sink. Now that everything is inside official-storybook, no need for two different approaches as we have full control over what test file is used. I already updated the README of the storyshots addon to document everything image-snapshots related. I believe this is sufficient, WDYT ? Please tell me in something is unclear. If you feel you need something else or not feel confident in something, please let me know. |
Creating a separate jest project may seem obvious, but I wouldn't qualify it as "nothing"
That's definitely worth documenting as well. There's quite a lot of CRA generated apps out there =) |
Well technically it's not required to create a separate Jest project, it eases the Jest configuration & especially for our use case with the test ran by That said, I tried to document this as much as I can, please forgive my english, don't hesitate to correct what does not make sense / is not english-valid sentences :) Thanks again for your help & patience on this, really appreciate it. Please let me know if anything needs more details! |
Thanks @thomasbertet , great work! @danielduan Your concerns are addressed, aren't they? |
@Hypnosphi see my answer : #2413 (comment). |
So are we good ? Are we waiting for @danielduan check ❓ |
|
@Hypnosphi you were so right, sorry did not notice it before .. anyway thanks ! |
My bad, been pretty busy recently. Looks good to me. |
👏 |
Should the css style testing portion of the docs be updated as well? By the way this is really great 👏 |
@anescobar1991 sounds like a plan! You want to open a PR adding it? |
Sure! Edit: opened #2767 with change |
This will not work on node 9+ |
Issue: #1781
What I did
How to test
yarn run test-image-snapshots
Is this testable with jest or storyshots?
Does this need a new example in the kitchen sink apps?
Does this need an update to the documentation?