philikon / ReactNativify

How to use node.js libraries in React Native
242 stars 23 forks source link

Do not remove .babelrc! May break Jest tests written in ES6 #8

Open aschrijver opened 7 years ago

aschrijver commented 7 years ago

I am using the ignite boilerplate and I just want to point out that you shouldn't delete the .babelrc file when replacing its content with babel-transformer.js!

Doing this leads to Jest tests stop working due to the ES6 code of the tests not being recognized properly. You get the dreaded:

FAIL  Tests/Sagas/StartupSagaTest.js
  ● Test suite failed to run

    /home/myself/MyProject/Tests/Sagas/StartupSagaTest.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { select, put } from 'redux-saga/effects';
                                                                                             ^^^^^^

    SyntaxError: Unexpected token import

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
      at handle (node_modules/worker-farm/lib/child/index.js:44:8)
      at process.<anonymous> (node_modules/worker-farm/lib/child/index.js:51:3)
      at emitTwo (events.js:125:13)

I did delete the .babelrc and it took me a ton of time to find the issue. Now I have this .babelrc in the root of the project:

{
  "env": {
    "test": {
      "presets": ["react-native"],
      "plugins": ["transform-es2015-modules-commonjs"]
    }
  }
}

And add NODE_ENV=test to the test task in package.json.