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
import test from 'ava'; test(t => { t.deepEqual([1, 2], [1, 2]); });
Advertisement
Answer
Add to your package.json
"ava": { "files": [ "test/**/*.js" ], "require": [ "babel-register" ], "babel": "inherit" },
Your .babelrc
{ "presets": ["es2015"] }
And then your imports should work.