I'm trying to have source files (and their dependencies in node_modules) be transpiled when running AVA tests. I've configured AVA to require babel-register
and inherit my .babelrc
file with the following in package.json
:
"ava": {
"require": "babel-register",
"babel": "inherit"
}
and this in .babelrc
:
{
"presets": [ "es2015" ],
"ignore": false
}
I have a test spec that imports a source file with and that source file imports an ES2015 dependency from node_modules:
However, when running 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 transpile, but it's dependency in node_modules (capitalize-string/index
) did not.
Both the source modules and dependencies transpile fine when I use babel CLI, so it really seems like the .babelrc
's "ignore": false
setting is not getting passed to babel-register
. I can see from the babel docs that you can explicitly pass an ignore option to babel-register
, but I don't see how you can do that from the AVA config. 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 suppose I could add a transpile step before testing, but I wanted to make sure that I wasn't just missing some AVA or babel configuration first.
This is related to issue in babel itself – https://phabricator.babeljs.io/T6726
But you can put babel-register
require in separate file (let call 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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With