I followed the docs to create my first test using ava but it doesn’t seem to run properly. I get the error below. I tried adding import 'babel-register';
at the top of the file, and it works, but only if I run one specific test file. e.g. ava ./test/helpers/test_helper.js
. Running ava
on its own though… results in the import error below. Does anyone else know how to fix this? The getting started guide uses ES6 import and I have no idea why mine doesn’t just work.
(function (exports, require, module, __filename, __dirname) { import test from ‘ava’; ^^^^^^ SyntaxError: Unexpected token import
test.js
JavaScript
x
6
1
import test from 'ava';
2
3
test(t => {
4
t.deepEqual([1, 2], [1, 2]);
5
});
6
Advertisement
Answer
Add to your package.json
JavaScript
1
10
10
1
"ava": {
2
"files": [
3
"test/**/*.js"
4
],
5
"require": [
6
"babel-register"
7
],
8
"babel": "inherit"
9
},
10
Your .babelrc
JavaScript
1
4
1
{
2
"presets": ["es2015"]
3
}
4
And then your imports should work.