Jestjs Jest从节点\模块组件导入意外令牌;巴贝尔跑不动了?

Jestjs Jest从节点\模块组件导入意外令牌;巴贝尔跑不动了?,jestjs,babel-jest,Jestjs,Babel Jest,我试图弄清楚如何让Jest在我的环境中工作,我遇到了一个问题,这个项目在node_模块的子目录中有一堆自定义组件 我得到了这个错误: FAIL src/mantle/tools/searchindexer/apps/DataMover/js/components/__test__/GenericJobsTable.test.jsx ● Test suite failed to run /Users/rob/repos/mesa/ui/node_modu

我试图弄清楚如何让Jest在我的环境中工作,我遇到了一个问题,这个项目在node_模块的子目录中有一堆自定义组件

我得到了这个错误:



    FAIL  src/mantle/tools/searchindexer/apps/DataMover/js/components/__test__/GenericJobsTable.test.jsx
      ● Test suite failed to run

        /Users/rob/repos/mesa/ui/node_modules/iggy-common/components/IggyTable.jsx:1
        ({"Object.":function(module,exports,require,__dirname,__filename,global,jest){import React, {PropTypes} from "react";
                                                                                                 ^^^^^^
        SyntaxError: Unexpected token import

          at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
          at Object. (src/mantle/tools/searchindexer/apps/DataMover/js/components/JobsTable/GenericJobsTable.jsx:7:18)
          at Object. (src/mantle/tools/searchindexer/apps/DataMover/js/components/__test__/GenericJobsTable.test.jsx:5:25)

    Test Suites: 1 failed, 1 total
    Tests:       0 total
    Snapshots:   0 total
    Time:        2.4s
    Ran all test suites matching "GenericJobsTable".

我正在nodejs7.7.1上运行
jest^20.0.3
babeljest^20.0.3

在my package.json中,这是我拥有的jest配置部分:



      "jest": {
        "verbose": true,
        "transform": {
          "^.+\\.jsx$": "babel-jest"
        },
        "moduleFileExtensions": [
          "js",
          "jsx"
        ],
        "moduleDirectories": [
          "node_modules"
        ]
      }

我将我的根
.babelrc
定义为:



    {
      "presets": ["es2015", "react"]
    }

如果我运行
jest--debug
我会看到:



    {
      "config": {
        "automock": false,
        "browser": false,
        "cache": false,
        "cacheDirectory": "/var/folders/wz/hd_hp8zn6gq7p6816w1hwx640000gn/T/jest_dx",
        "clearMocks": false,
        "coveragePathIgnorePatterns": [
          "/node_modules/"
        ],
        "globals": {},
        "haste": {
          "providesModuleNodeModules": []
        },
        "moduleDirectories": [
          "node_modules"
        ],
        "moduleFileExtensions": [
          "js",
          "jsx"
        ],
        "moduleNameMapper": {},
        "modulePathIgnorePatterns": [],
        "name": "898fa528b40c10619090191345fdb241",
        "resetMocks": false,
        "resetModules": false,
        "rootDir": "/Users/rob/repos/mesa/ui",
        "roots": [
          "/Users/rob/repos/mesa/ui"
        ],
        "setupFiles": [
          "/Users/rob/repos/mesa/ui/node_modules/regenerator-runtime/runtime.js"
        ],
        "snapshotSerializers": [],
        "testEnvironment": "jest-environment-jsdom",
        "testMatch": [
          "**/__tests__/**/*.js?(x)",
          "**/?(*.)(spec|test).js?(x)"
        ],
        "testPathIgnorePatterns": [
          "/node_modules/"
        ],
        "testRegex": "",
        "testRunner": "/Users/rob/repos/mesa/ui/node_modules/jest-jasmine2/build/index.js",
        "testURL": "about:blank",
        "timers": "real",
        "transform": [
          [
            "^.+\\.jsx$",
            "/Users/rob/repos/mesa/ui/node_modules/babel-jest/build/index.js"
          ]
        ],
        "transformIgnorePatterns": [
          "/node_modules/"
        ]
      },
      "framework": "jasmine2",
      "globalConfig": {
        "bail": false,
        "coverageReporters": [
          "json",
          "text",
          "lcov",
          "clover"
        ],
        "expand": false,
        "mapCoverage": false,
        "noStackTrace": false,
        "notify": false,
        "projects": [
          "/Users/rob/repos/mesa/ui"
        ],
        "rootDir": "/Users/rob/repos/mesa/ui",
        "testPathPattern": "",
        "testResultsProcessor": null,
        "updateSnapshot": "new",
        "useStderr": false,
        "verbose": true,
        "watch": false,
       "watchman": true
      },
      "version": "20.0.3"
    }


你知道我在这里可能误解了什么吗?

解决了!!!!!问题是node_modules/iggy common中的一个讨厌的文件是一个普通的ol'JS文件,需要进行转换:


  "jest": {
    "verbose": true,
    "transform": {
      "^.+\\.jsx$": "babel-jest",
      "^.+\\.js$": "babel-jest"
    },
    "moduleFileExtensions": [
      "js",
      "jsx"
    ],
    "moduleDirectories": [
      "node_modules"
    ],
    "transformIgnorePatterns": [
      "node_modules/(?!iggy-common)"
    ]      
  }


从我收集的信息来看,jest babel不在node_modules目录下传输任何内容似乎存在问题……但我确实希望它在node_modules/iggy Common下传输任何内容。这一额外的(?!pkg)对我来说至关重要。