2017-05-18 30 views
10

Próbuję dowiedzieć się, jak dostać się żartem do pracy w moim otoczeniu, i używam do problemu gdzie projekt ten ma kilka niestandardowych składników w podkatalogu w node_modules.Jest to nieoczekiwany import tokena ze składnika node_modules; Babel nie biegnie?

Dostaję taki błąd:



    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". 

biegnę jest ^20.0.3 i babel-jest ^20.0.3 na NodeJS 7.7.1.

W moim package.json, to JEST sekcji config mam:



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

Mam korzeń .babelrc zdefiniowany jako:



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

Jeśli biegnę jest --debug widzę tak:



    { 
     "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" 
    } 

Jakiś pomysł, który mógłbym tutaj źle skonfigurować?

+0

Z czego wnoszę, wydaje się, że nie musi być problem z żartem-babel nie transponuje niczego pod katalogiem node_modules ... ale ja * DO * chcę, żeby to było transpozycja czegokolwiek pod węzłem node_modules/iggy-common –

Odpowiedz

16

SOLVED !!!!! Problem likwidacji jest, że jeden z tych nieznośnych plików w node_modules/Iggy-common był zwykły ol”JS plik konieczności transpilation:


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

Powiązane problemy