Jestjs 巴贝尔开玩笑不';我不能开玩笑
我有一个作为插件的代码文件夹,所以它是主目录的子目录。主目录正确运行使用导入语句的测试,但子文件夹不正确。子文件夹有自己的。它们发布在下面 B.法律改革委员会Jestjs 巴贝尔开玩笑不';我不能开玩笑,jestjs,babeljs,babel-jest,Jestjs,Babeljs,Babel Jest,我有一个作为插件的代码文件夹,所以它是主目录的子目录。主目录正确运行使用导入语句的测试,但子文件夹不正确。子文件夹有自己的。它们发布在下面 B.法律改革委员会 { "presets": [ "@babel/preset-env" ], "plugins": [ ["@babel/plugin-proposal-decorators", { "legacy": true }], "@babel/plugin
{
"presets": [
"@babel/preset-env"
],
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true }],
"@babel/plugin-proposal-function-sent",
"@babel/plugin-proposal-export-namespace-from",
"@babel/plugin-proposal-numeric-separator",
"@babel/plugin-proposal-throw-expressions",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-runtime",
"@babel/plugin-transform-modules-commonjs",
[
"module-resolver",
{
"alias": {
"example-lib": "./src"
}
}
]
],
"env": {
"test": {
"presets": [
[
"@babel/preset-env",
{
"modules": "commonjs"
}
]
]
}
}
}
package.json
"jest": {
"transform": {
"^.+\\.jsx?$": "babel-jest"
}
}
"devDependencies": {
"@babel/core": "^7.3.4",
"@babel/plugin-transform-modules-commonjs": "^7.2.0",
"@babel/preset-env": "^7.3.4",
"example-lib": "^0.11.4",
"babel-jest": "^24.5.0"
},
开玩笑——调试
错误本身:
● Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
/Users/user/development/repo/lib/plugin/test/SystemDataService.spec.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { example } from './helpers';
^
SyntaxError: Unexpected token {
at ScriptTransformer._transformAndBuildScript (../../node_modules/jest-runtime/build/ScriptTransformer.js:440:17)
● 测试套件无法运行
Jest遇到了意外的标记
这通常意味着您正试图导入Jest无法解析的文件,例如,它不是纯JavaScript。
默认情况下,如果Jest看到一个Babel配置,它将使用它来转换您的文件,忽略“node_modules”。
以下是您可以做的:
•要转换某些“节点模块”文件,可以在配置中指定自定义“transformIgnorePatterns”。
•如果需要自定义转换,请在配置中指定“转换”选项。
•如果您只是想模拟您的非JS模块(例如二进制资产),您可以使用“moduleNameMapper”配置选项将其剔除。
您将在文档中找到这些配置选项的更多详细信息和示例:
https://jestjs.io/docs/en/configuration.html
细节:
/Users/user/development/repo/lib/plugin/test/SystemDataService.spec.js:1
({“Object.”:函数(模块、导出、require、u dirname、u filename、全局、jest){import{example}from./helpers';
^
SyntaxError:意外标记{
在ScriptTransformer.\u transformAndBuildScript(../../node\u modules/jest runtime/build/ScriptTransformer.js:440:17)
● Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
/Users/user/development/repo/lib/plugin/test/SystemDataService.spec.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { example } from './helpers';
^
SyntaxError: Unexpected token {
at ScriptTransformer._transformAndBuildScript (../../node_modules/jest-runtime/build/ScriptTransformer.js:440:17)