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

Fix image snapshots setup in official-storybook #8932

Merged
merged 4 commits into from
Nov 25, 2019
Merged

Conversation

Hypnosphi
Copy link
Member

Issue: yarn image-snapshots in examples/official-storybook doesn't work

What I did

  1. Reused toRequireContext in storyshots to match the behaviour of @storybook/core
  2. Replaced glob-regex with micromatch.makeRe as the former only supports very basic patterns
  3. Added a customisable timeout for storyshot-puppeteer setup and tests

@vercel
Copy link

vercel bot commented Nov 23, 2019

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/storybook/monorepo/iify2jvoe
🌍 Preview: https://monorepo-git-fix-image-snapshot.storybook.now.sh

output.stories = stories.map(
(pattern: string | { path: string; recursive: boolean; match: string }) => {
const { path: basePath, recursive, match } = toRequireContext(pattern);
return require.context(
Copy link
Member

Choose a reason for hiding this comment

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

🤔 how does this work in Jest? I didn't think require.context() existed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Oh, right but this isn't universal. For instance:

  1. Users may be using the babel macro
  2. This code was added to actually avoid needing to use babel at all if they are using the main.js entrypoint.

What was the issue with what was there before w/ more typical require()s?

Copy link
Member

Choose a reason for hiding this comment

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

Also it is unlikely that user's code is going to run their babel plugins over files in node_modules. Or is all this being compiled when we compile addon/storyshots?

Copy link
Member Author

@Hypnosphi Hypnosphi Nov 25, 2019

Choose a reason for hiding this comment

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

Or is all this being compiled when we compile addon/storyshots?

It is but require-context plugin isn't applied right now, I'll add that, thanks for noting.
UPD: it's tsc not babel, so I think I'll just import babel-plugin-require-context-hook/register and use global.__requireContext directly

What was the issue with what was there before w/ more typical require()s?

We used different libraries for turning globs into files in core and storyshots which sometimes led to differences. For instance, "regex or" patterns (.stories.(js|tsx|mdx)) that we use in main.js aren't supported by node-glob

Copy link
Member

Choose a reason for hiding this comment

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

Ok, that makes sense.

@vercel vercel bot temporarily deployed to staging November 25, 2019 02:49 Inactive
# Conflicts:
#	addons/storyshots/storyshots-core/package.json
if (getCustomBrowser) {
browser = await getCustomBrowser();
} else {
// eslint-disable-next-line global-require
const puppeteer = require('puppeteer');
Copy link
Member

Choose a reason for hiding this comment

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

You may want to try TS dynamic import: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-4.html#dynamic-import-expressions & https://basarat.gitbooks.io/typescript/docs/project/dynamic-import-expressions.html
I don't know if it will work on this case because I don't have a full knowledge of how storyshots-puppeteer works.

Copy link
Member Author

Choose a reason for hiding this comment

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

Does it work in Node 10?

@Hypnosphi Hypnosphi merged commit dc02a4f into next Nov 25, 2019
@Hypnosphi Hypnosphi deleted the fix-image-snapshot branch November 25, 2019 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants