开玩笑不导入ES6模块(具有正确的transformIgnorePatterns)

时间:2019-09-13 14:20:58

标签: javascript ecmascript-6 jestjs babel babel-jest

我正在开玩笑并出现错误:

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.jsnode_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"
      ]
    }

0 个答案:

没有答案