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

Include macro instructions for Storyshots docs #5015

Merged
merged 1 commit into from
Dec 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions addons/storyshots/storyshots-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ other tools may lack this feature. Since Storyshot is running under Jest,
we need to polyfill this functionality to work with Jest. The easiest
way is to integrate it to babel.

One of the possible babel plugins to
polyfill this functionality might be
[babel-plugin-require-context-hook](https://github.com/smrq/babel-plugin-require-context-hook).
You can do this with a Babel [plugin](https://github.com/smrq/babel-plugin-require-context-hook) or [macro](https://github.com/storybooks/require-context.macro). If you're using `create-react-app` (v2 or above), you will use the macro.

- *Plugin*

First, install it:

Expand Down Expand Up @@ -88,6 +88,23 @@ Finally, add the plugin to `.babelrc`:
```
The plugin is only added to the test environment otherwise it could replace webpack's version of it.

- *Macro*

First, install it:

```sh
npm install --save-dev require-context.macro
```

Now, inside of your Storybook config file, simply import the macro and run it in place of `require.context`, like so:

```javascript
import requireContext from 'require-context.macro';

// const req = require.context('../stories', true, /.stories.js$/); <-- replaced
const req = requireContext('../stories', true, /.stories.js$/);
```

### Configure Jest for React
StoryShots addon for React is dependent on [react-test-renderer](https://github.com/facebook/react/tree/master/packages/react-test-renderer), but
[doesn't](#deps-issue) install it, so you need to install it separately.
Expand Down