reactstrap icon indicating copy to clipboard operation
reactstrap copied to clipboard

Jest test failing

Open dubtar opened this issue 8 years ago • 10 comments

Issue description

  • components: any
  • reactstrap version #5.0.0-beta.2
  • import method es(typescript) (if umd, are you using the "full" version (only for v5+)?)
  • react version #16.2.0

What is happening?

Any Jest test in app created by create-react-app fail to run.

Steps to reproduce issue

  1. create-react-app my-app --scripts-version=react-scripts-ts
  2. npm install --save [email protected] @types/reactstrap
  3. import and use any reactstrap component to App.ts, for ex. Container
  4. npm run test

Error message in console

  ● Test suite failed to run

    C:\temp\my-app\node_modules\react-popper\lib\react-popper.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export { default as Manager } from './Manager';
                                                                                             ^^^^^^

    SyntaxError: Unexpected token export

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
      at Object.<anonymous> (node_modules/reactstrap/dist/reactstrap.cjs.js:14:19)
      at Object.<anonymous> (src/App.tsx:15:20)

I don't think the reason is typescript. As I understood, Jest runs as node process, and create-react-app setup jest to not transpile any files under node_modules folder. Since react-popper/package.json conains "main": "lib/react-popper.js", and version under /lib contains es6' export statements, node finally gets those export statements and fails. If I change react-popper/package.json to point main to dist: "main": "dist/react-popper.js", tests pass.

dubtar avatar Feb 28 '18 08:02 dubtar

I can only confirm I have the very same issue. My app is created using create-react-apps

 src/App/App.test.js
  ● Test suite failed to run

    /Users/venelin/projects/stylbum-web-v2/node_modules/react-popper/lib/react-popper.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export { default as Manager } from './Manager';
                                                                                             ^^^^^^

    SyntaxError: Unexpected token export

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
      at Object.<anonymous> (node_modules/reactstrap/dist/reactstrap.cjs.js:14:19)

vmanchev avatar Feb 28 '18 10:02 vmanchev

I am also seeing the same issue.

benbxyz avatar Feb 28 '18 10:02 benbxyz

So do I( I think it is react-popper issue.

sinxwal avatar Feb 28 '18 11:02 sinxwal

Quick fix - revert to "reactstrap": "5.0.0-beta". It has older react-popper version.

sinxwal avatar Feb 28 '18 12:02 sinxwal

Same issue

justinlevi avatar Feb 28 '18 15:02 justinlevi

same cause, but made my react projects cannot run in node.js for server rendering i saw once that #835 has upgraded the react-popper to ^0.8.2, in which the release of the [email protected] has correctly transformed babel-fied JSX code in lib/, but for some reason the ^0.8.2 description in package.json is being rewritten back as 0.8.1

soumasandesu avatar Mar 01 '18 02:03 soumasandesu

https://github.com/reactstrap/reactstrap/commit/b515e6bbb137443550f9ea7b0b2ba48113ebd169 reverted the updated react-popper down to 0.8.1. That commit claims to fix the broken build, so I'm not sure what is going on as it does the opposite for me.

rtkmrussell avatar Mar 01 '18 16:03 rtkmrussell

Same issue here. Reverted my reactstrap version to 5.0.0-beta and it is resolved. Thanks @sinxwal

MichaelDurfey avatar Mar 01 '18 18:03 MichaelDurfey

Same here, any news?

alvarosabu avatar Mar 15 '18 23:03 alvarosabu

The PR in react-popper has been merged, just waiting on it to be published in a release.

TheSharpieOne avatar Mar 15 '18 23:03 TheSharpieOne