我正在开玩笑并出现错误:
Test suite failed to run
/atol/node-service/node_modules/atol-atoms/Grids/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import _Row from "./Row";
^^^^
SyntaxError: Unexpected identifier
> 1 | import {Container, Row, Cell} from 'atol-atoms/Grids';
atol-atoms
是一个组件库,我需要使用babel进行转换才能使用。它可以与webpack一起使用,但是当我运行测试时,它失败了。
我的依赖项:
"@babel/plugin-transform-runtime": "^7.6.0",
"@babel/polyfill": "^7.6.0",
"@babel/preset-env": "^7.6.0",
"@babel/preset-react": "^7.0.0",
"babel-jest": "^24.9.0",
"jest": "^24.9.0",
如果我需要jest.config.js
和node_modules
中的转换模块,我认为babel-jest
中的下一个配置应该可以工作:
transformIgnorePatterns: [
'<rootDir>/node_modules/(?!(atol-atoms)/)'
],
此外,我在env.test
部分中使用了正确的.babelrc:
"test": {
"plugins": [
"@babel/plugin-transform-runtime",
"@babel/plugin-proposal-class-properties"
],
"presets": [
[
"@babel/preset-env",
{
"debug": true
}
],
"@babel/preset-react"
]
}