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

revisit the jest import error and our workaround #48

Closed
fczuardi opened this issue Oct 16, 2017 · 1 comment · Fixed by #49
Closed

revisit the jest import error and our workaround #48

fczuardi opened this issue Oct 16, 2017 · 1 comment · Fixed by #49

Comments

@fczuardi
Copy link
Contributor

Currently we are using an ugly workaround to avoid the jest / babel bug that causes jest to not transpile es modules imports.

The workaround is to re-add jest as a dev dependency after installing everything, see:

- yarn add -D jest

But after updating yarn to 1.2.1 that workaround will no longer work. So we need a permanent fix.

Some (old?) references / hints:

@fczuardi
Copy link
Contributor Author

ok, so here is the error:

 FAIL  ./Storyshots.test.js
  ● Test suite failed to run

    /Users/fabricio/mnmo/active/crave/farmblocks/node_modules/@crave/farmblocks-alert/src/index.story.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import React from "react";
                                                                                             ^^^^^^

    SyntaxError: Unexpected token import

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:305:17)
      at node_modules/@storybook/addon-storyshots/dist/require_context.js:39:24
          at Array.forEach (<anonymous>)
      at requireModules (node_modules/@storybook/addon-storyshots/dist/require_context.js:34:9)
      at node_modules/@storybook/addon-storyshots/dist/require_context.js:48:7
          at Array.forEach (<anonymous>)

After some investigation, the problem seem to be with the storybook config file, that currently use the following regex to find story.js files:

const req = require.context("../", true, /\.story\.js$/);

And this broad regex will include .story.js files that lives under node_modules, and packages/something/node_modules :(

I will submit a PR with a better regex that exclude node_modules subfolders...

fczuardi added a commit that referenced this issue Oct 16, 2017
…ies from node_modules caused in

the require.context files list was including story files from inside node_modules

ISSUES CLOSED: #48
@seocam seocam removed the review label Oct 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants