question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Storybook doesn't work when I follow the tutorial in the Snapshot Test config

See original GitHub issue

Describe the bug I’m creating a library with create-react-library package, but this error occur with the create-react-app too. When I follow the tutorial storybook works fine, but when I

To Reproduce Steps to reproduce the behavior:

  1. Create a project with create-react-library or create-react-app
  2. Init storybook in project
  3. Create a component for test
  4. Install packages @storybook/addon-storyshots react-test-renderer require-context.macro
  5. Create src/storybook.test.js with:

import initStoryshots from '@storybook/addon-storyshots'; initStoryshots();

  1. Change .storybook/config.js with:
import { configure } from '@storybook/react';
import requireContext from 'require-context.macro';

import '../src/index.css';

const req = requireContext('../src/components', true, /\.stories\.js$/);

function loadStories() {
  req.keys().forEach(filename => req(filename));
}

configure(loadStories, module);
  1. Execute yarn test and catch

MacroError: The macro you imported from “undefined” is being executed outside the context of compilation with babel-plugin-macros. This indicates that you don’t have the babel plugin “babel-plugin-macros” configured correctly. Please see the documentation for how to configure babel-plugin-macros properly: https://github.com/kentcdodds/babel-plugin-macros/blob/master/other/docs/user.md

  1. Execute yarn storybook and catch

WARNING in ./node_modules/babel-plugin-macros/dist/index.js 73:24-31 Critical dependency: require function is used in a way in which dependencies cannot be statically extracted @ ./node_modules/require-context.macro/require-context.macro.js @ ./.storybook/config.js @ multi ./node_modules/@storybook/core/dist/server/common/polyfills.js ./node_modules/@storybook/core/dist/server/preview/globals.js ./.storybook/config.js (webpack)-hot-middleware/client.js?reload=true

WARNING in ./node_modules/import-fresh/index.js 28:8-25 Critical dependency: the request of a dependency is an expression @ ./node_modules/cosmiconfig/dist/loaders.js @ ./node_modules/cosmiconfig/dist/index.js @ ./node_modules/babel-plugin-macros/dist/index.js @ ./node_modules/require-context.macro/require-context.macro.js @ ./.storybook/config.js @ multi ./node_modules/@storybook/core/dist/server/common/polyfills.js ./node_modules/@storybook/core/dist/server/preview/globals.js ./.storybook/config.js (webpack)-hot-middleware/client.js?reload=true

Expected behavior I expected to execute the tests and show if they works or no, and show storybook page with my stories.

Code snippets I upload the complete code https://github.com/ArmandoAA/storybook-error-with-snapshot-tests

System:

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:6

github_iconTop GitHub Comments

3reactions
halian-vilelacommented, Jul 3, 2019

Hey guys, try this:

  1. Install babel-plugin-macros --> yarn add babel-plugin-macros
  2. Add a .babelrc to root folder with
{
  "plugins": ["macros"]
}
  1. Restart Storybook.

See if it works

2reactions
halian-vilelacommented, Jul 26, 2019

I have a PR running on this issue, maybe it will make it clear if went directly into the docs. Looking forward for it to be merged.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Snapshot tests
Storyshots is the official Storybook addon that enables snapshot testing, powered by Jest. Run the following command to install Storyshots: YARN; NPM.
Read more >
Storyshots Addon | Storybook: Frontend workshop for UI ...
To use StoryShots, you must use your existing Storybook stories as the input for Jest Snapshot Testing. Getting Started. Add the following module...
Read more >
Frequently Asked Questions - Storybook - JS.ORG
Storybook is a frontend workshop for building UI components and pages in isolation. Thousands of teams use it for UI development, testing, and...
Read more >
Interaction tests - Storybook - JS.ORG
How does component testing in Storybook work? You start by writing a story to set up the component's initial state. Then simulate user...
Read more >
Visual testing in Storybook
Visual testing catches bugs by capturing and comparing image snapshots in a ... you run a function, get its output and check whether...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found