2017-10-21 154 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语法编写它就可以工作。