ava: SyntaxError: Unexpected token import

元气小坏坏 提交于 2019-11-30 10:53:23
thangngoc89

AVA only transpile the test files. Not test dependencies so you will need to setup babel in your project (I suppose you did it because you're using ES6 anyway).

Then in AVA's setting, add this :

"ava": {
  ...
  "babel": "inherit"
}

It means that use your project babel setting to transpile the test dependencies. See more information in AVA docs: https://github.com/sindresorhus/ava/blob/master/docs/recipes/babelrc.md

Jason Kim

Using rweng, my solution came out a bit simpler.

  1. .babelrc
{
  "presets": [
    "es2015"
  ],
  "plugins": [
    "transform-runtime"
  ]
}
  1. package.json:
"ava": {
  "require": ["babel-register"],
  "babel": "inherit"
}

Unfortunately standard solution didn't work for my case. Here is my solution which worked for ava + quasar + vue project

.babelrc

{
  "presets": [
    "es2017",
    "@ava/stage-4",
    "stage-3"
  ],
  "plugins": [
    "transform-runtime"
  ]
}

package.json

"ava": {
  "require": [
    "babel-register"
  ],
  "babel": "inherit"
},
"scripts": {
  "ava": "NODE_ENV=test ava",
  "test": "ava",
  "test:watch": "ava --watch --verbose"
}

install modules

yarn add babel-register babel-preset-es2017 @ava/babel-preset-stage-4 babel-plugin-transform-runtime babel-preset-stage-3 --dev
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!