我正在尝试在运行AVA测试时编译源文件(以及它们在node_modules中的依赖项).我已将AVA配置为要求babel-register并继承我的.babelrc文件,其中包含以下内容package.json:
"ava": {
"require": "babel-register",
"babel": "inherit"
}
Run Code Online (Sandbox Code Playgroud)
这个在.babelrc:
{
"presets": [ "es2015" ],
"ignore": false
}
Run Code Online (Sandbox Code Playgroud)
我有一个测试规范,用于导入源文件,该源文件从node_modules导入ES2015依赖项:
但是,在运行时ava我看到:
/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
Run Code Online (Sandbox Code Playgroud)
这告诉我源文件(src/app/utils.js)确实是转换的,但它在node_modules(capitalize-string/index)中的依赖性没有.
当我使用babel CLI时,源模块和依赖项都转换得很好,所以看起来它.babelrc的"ignore": false设置似乎没有传递给它babel-register.我可以从babel文档中看到你可以显式传递一个忽略选项babel-register,但我不知道如何从AVA配置中做到这一点.我甚至尝试在导入源文件的行之前将以下内容添加到我的测试文件中,但我仍然看到相同的错误:
require("babel-register")({
ignore: false
});
Run Code Online (Sandbox Code Playgroud)
我想我可以在测试前添加一个简单的步骤,但我想确保我不是首先错过了一些AVA或babel配置.
这与 babel 本身的问题有关 \xe2\x80\x93 https://phabricator.babeljs.io/T6726
\n\n但是你可以将babel-registerrequire 放在单独的文件中(我们称之为.setup.js):
require(\'babel-register\')({\n ignore: /node_modules\\/(?!capitalize\\-word)/i\n});\n\nconst noop = function () {};\n\nrequire.extensions[\'.css\'] = noop; // If you want to ignore some CSS imports\nRun Code Online (Sandbox Code Playgroud)\n\n然后更改"require": "babel-register"为"require": "./.setup.js"
| 归档时间: |
|
| 查看次数: |
1153 次 |
| 最近记录: |