2017-10-21 174 views
1

我是新來的笑話。我遇到了圓形CI上的錯誤。我的setup.js文件具有ES6語法。由於每次運行測試時都會執行setupTestFrameworkScriptFile上的文件,因此我認爲我可以使用ES6語法,但babel-jest不會將其傳輸。定期測試,例如反應組分的單元測試被傳輸。在本地環境中,安裝文件會被轉儲。Jest setupTestFrameworkScriptFile或setupFiles ES6語法

SyntaxError: Unexpected token { 

     at ScriptTransformer._transformAndBuildScript (node_modules/jest/node_modules/jest-cli/node_modules/jest-runtime/build/script_transformer.js:305:17) 
     at Object.<anonymous> (test/setup.js:1:869) 
     at next (native) 

我的笑話配置文件看起來像這樣。

{ 
    "verbose": true, 
    "transform": { 
    "^.+\\.(js|jsx)$": "babel-jest" 
    }, 
    "transformIgnorePatterns": [ 
    "node_modules/(?!my-module)" 
    ], 
    "snapshotSerializers": [ 
    "jest-serializer-enzyme" 
    ], 
    "setupTestFrameworkScriptFile": "<rootDir>/test/setup.js", 
    "globals": { 
    "__PROD__": false, 
    "__STG__": false 
    }, 
    "moduleDirectories": [ 
    "node_modules" 
    ], 
    "testRegex": "(/__tests__/.*|__test__.js)$", 
    "moduleFileExtensions": [ 
    "css", 
    "jsx", 
    "js", 
    "scss", 
    "svg" 
    ], 
    "moduleNameMapper": { 
    "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/test/fileMock.js", 
    "^.+\\.(css|less|scss)$": "<rootDir>/test/styleMock.js" 
    } 
} 

我是否錯過任何設置?

+0

你如何運行你的測試?最新的Node版本本身支持ES6(當然除了模塊語法)。 –

回答

1

Jest不會將setup.js腳本通過轉碼步驟。 Jest會傳輸你的測試代碼,然後運行你的設置腳本而不需要進行轉譯,然後運行你的測試代碼。只需用ES5語法編寫它就可以工作。