Using babel-register with AVA and .babelrc `` ignore ": false`, but node_modules do not overflow

I am trying to transfer the source files (and their dependencies to node_modules) while running AVA tests. I configured AVA to require babel-register and inherit my .babelrc file with the following: package.json :

 "ava": { "require": "babel-register", "babel": "inherit" } 

and this is in .babelrc :

 { "presets": [ "es2015" ], "ignore": false } 

I have a test specification that imports the source file , and that the source file imports the ES2015 dependency on node_modules :

However, when I run ava I see:

 /Users/me/code/esri-rollup-example/node_modules/capitalize-word/index.js:2 export default input => input.replace(regexp, match => match.charAt(0).toUpperCase() + match.substr(1)); ^^^^^^ SyntaxError: Unexpected token export 

Which tells me that the source file ( src/app/utils.js ) did forward, but its dependency in node_modules ( capitalize-string/index ) did not execute.

Both the source modules and the dependencies are well ported when I use the CLI for babel, so it really seems that the .babelrc parameter "ignore": false not passed to babel-register . From the babel docs, I can see that you can explicitly pass the ignore option to babel-register , but I don't see how you can do this from the AVA configuration. I even tried adding the following to my test file before the line where it imports the source files, but I still see the same error:

 require("babel-register")({ ignore: false }); 

I believe that before testing I could add a forwarding step, but I wanted to make sure that I did not just skip the AVA or Babel configuration first.

+6
source share
1 answer

This is due to a problem in the granny herself - https://phabricator.babeljs.io/T6726

But you can put babel-register in a separate file (name it .setup.js ):

 require('babel-register')({ ignore: /node_modules\/(?!capitalize\-word)/i }); const noop = function () {}; require.extensions['.css'] = noop; // If you want to ignore some CSS imports 

And then change "require": "babel-register" to "require": "./.setup.js"

+4
source

All Articles