问题描述
因此ava附带了内置ES2015支持,对于我的实际情况来说效果很好测试文件.但是,当我这样做
So ava comes with build-in ES2015 support, which works fine for my actual test files. However, when I do
.I have no specific babel configuration set up as for the test files it works out of the box. Can anyone explain to me why the helper dependencies are not transpiled with babel? Using test/**/helpers is even following ava convention.
谢谢, 罗宾
解决方案
因此,根据 thangngoc89 的解决方案,我所做的工作是:
So based on thangngoc89's solution, what I did to make it work was:
- 添加具有内容的.babelrc
{ "presets": [ "es2015", "stage-2" ], "plugins": [ "espower", "transform-runtime" ] }
- 已添加到package.json:
"ava": { "require": ["babel-register"], "babel": "inherit" }推荐答案
AVA仅转储测试文件.不测试依赖项,因此您将需要在项目中设置babel(我想是因为您一直在使用ES6才这样做的.)
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).
然后在AVA的设置中,添加以下内容:
Then in AVA's setting, add this :
"ava": { ... "babel": "inherit" }这意味着使用您的项目babel设置来转换测试依赖项.请参阅AVA文档中的更多信息: https://github.com/sindresorhus/ava/blob/master/docs/recipes/babelrc.md
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
这篇关于ava:SyntaxError:意外的令牌导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!