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

Storyshots: First-class CSF support #8000

Merged
merged 15 commits into from Oct 4, 2019
Merged

Storyshots: First-class CSF support #8000

merged 15 commits into from Oct 4, 2019

Conversation

Hypnosphi
Copy link
Member

@Hypnosphi Hypnosphi commented Sep 5, 2019

Issue: #7697

What I did

– Migrated sample stories in storyshots-core to CSF
Used displayName in generated test names reverted in favor of #7878 (comment)
– Added detection of fileName from req. It won't work with babel-plugin-require-context-hook until smrq/babel-plugin-require-context-hook#9 gets merged and released. Same for require-context.macro storybookjs/require-context.macro#13
– Added @storybook/addon-storyshots/injectFileName transform that adds exports.default.patameters.fileName. Added a warning suggesting to include this transform when getSnapshotFileName is called but fileName is falsy.

@vercel
Copy link

vercel bot commented Sep 5, 2019

This pull request is automatically deployed with Now.
To access deployments, click Details below or on the icon next to each push.

Latest deployment for this branch: https://monorepo-git-storyshots-csf.storybook.now.sh

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great @Hypnosphi 💯

I had a few minor changes inline -- should be an easy fix.

Also, I'm wondering if you've seen this PR that's vaguely related: #7330

I haven't had a chance to address it yet, but I'm wondering if it influences this PR at all? (It might not, just asking.)

@shilman
Copy link
Member

shilman commented Sep 5, 2019

@Hypnosphi are there tests to make sure it still works well with the storiesOf files?

@vercel vercel bot temporarily deployed to staging September 5, 2019 06:46 Inactive
@Hypnosphi
Copy link
Member Author

Ok, I'll revert some of the stories

@kylemh
Copy link
Member

kylemh commented Sep 6, 2019

Merged storybookjs/require-context.macro#13 and released as v1.2.0

@shilman
Copy link
Member

shilman commented Sep 6, 2019

@kylemh anything required on the storybook side, or is that just an FYI? AFAIK it's not a storybook dep

@kylemh
Copy link
Member

kylemh commented Sep 6, 2019

@shilman just an FYI! Nothing needed more from us.

Note Hypno's 3rd bullet in OP.

@Hypnosphi
Copy link
Member Author

Hypnosphi commented Sep 6, 2019

@shilman it's one of the solutions to require.context problem we suggest in our docs.

@shilman
Copy link
Member

shilman commented Sep 6, 2019

@kylemh @Hypnosphi thanks for the clarification. i know about the package -- just missed the ref in your original PR @Hypnosphi . makes sense! 👍

# Conflicts:
#	addons/storyshots/storyshots-core/package.json
@ndelangen ndelangen added this to the 5.3.0 milestone Oct 3, 2019
# Conflicts:
#	examples/preact-kitchen-sink/src/stories/__snapshots__/welcome.stories.storyshot
@Hypnosphi
Copy link
Member Author

@shilman can you please re-review?

@shilman shilman changed the title First-class support of CSF in Storyshots Storyshots: First-class CSF support Oct 4, 2019
Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really great work @Hypnosphi. Thanks so much for taking care of this 🙏

@shilman
Copy link
Member

shilman commented Oct 4, 2019

@Hypnosphi can you take a look at the failing story in Chromatic?

@Hypnosphi
Copy link
Member Author

Hypnosphi commented Oct 4, 2019

@shilman looks like at some point @ndelangen switched chromatic to use production build, and in production webpack replaces filenames with numbers. It won't be a problem in storyshot tests.

I think I'll filter out the fileName parameter from this story to avoid confusion

@vercel vercel bot temporarily deployed to staging October 4, 2019 10:03 Inactive
# Conflicts:
#	addons/storyshots/storyshots-core/package.json
@shilman shilman merged commit 26fe5aa into next Oct 4, 2019
@shilman shilman deleted the storyshots-csf branch October 4, 2019 10:57
@shilman shilman added the patch:done Patch/release PRs already cherry-picked to main/release branch label Oct 7, 2019
shilman added a commit that referenced this pull request Oct 7, 2019
Storyshots: First-class CSF support
// jest.config.js
module.exports = {
transform: {
'^.+\\.stories\\.jsx?$': '@storybook/addon-storyshots/injectFileName',
Copy link
Contributor

@JohnAlbin JohnAlbin Oct 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This documentation change differs from what is displayed in the warning below. https://github.com/storybookjs/storybook/pull/8000/files#diff-c4bcb815683c4c92762d0a868383a06cR38

Storybook was unable to detect filename for stories of kind "${kind}".
To fix it, add following to your jest.config.js:
    transform: {
      // should be above any other js transform like babel-jest
      '^.+\\\\.stories\\\\.js$': '@storybook/addon-storyshots/injectFileName',
    }

Which one is the correct advice?

Yes, I know that \\\\ is the JS equivalent of two backslashes output. However, I'm seeing all 4 backslashes on the console.

Screen Shot 2019-10-11 at 7 09 06 PM

Hmm… I guess I answered my own question. I should be using two backslashes in my Jest config. The bug is in the console warning showing 4 backslashes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addon: storyshots bug csf patch:done Patch/release PRs already cherry-picked to main/release branch patch:yes Bugfix & documentation PR that need to be picked to main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants