下面是我尝试运行jest命令时遇到的问题。
jest --config jest.config.json
失败测试\ Home.spec.js ?测试套件无法运行
SyntaxError: Unexpected reserved word at transformAndBuildScript(node_modules\jest\node_modules\jest-cli\node_modules\jest-runtime\build\transform.js:320:12)
以下是我的配置。 Package.json与webpack,jest版本
{
"name": "testjest",
"version": "1.0.0",
"description": "Test React and Redux using Jest",
"main": "index.js",
"license": "MIT",
"scripts": {
"dev": "webpack-dev-server --content-base --inline --hot",
"test": "jest --config jest.config.json"
},
"dependencies": {
"babel-preset-es2015": "^6.18.0",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-0": "^6.16.0",
"react": "^15.4.1",
"react-dom": "^15.4.1",
"react-redux": "^5.0.1",
"redux": "^3.6.0"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-jest": "^21.2.0",
"babel-loader": "^6.2.10",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
"core-js": "^2.4.0",
"enzyme": "^2.7.0",
"jest": "^18.1.0",
"json-stable-stringify": "^1.0.1",
"react-addons-test-utils": "^15.4.1",
"react-test-renderer": "^15.4.1",
"redux-mock-store": "^1.2.1",
"regenerator-runtime": "^0.11.0",
"regenerator-transform": "^0.10.0",
"identity-obj-proxy": "3.0.0",
"webpack": "^1.14.0",
"webpack-dev-server": "^1.16.2"
}
}
这是我的jest json配置文件。
{
"moduleFileExtensions": [
"js",
"jsx"
],
"moduleDirectories": ["node_modules", "bower_components", "shared"],
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
"<rootDir>/__mocks__/fileMock.js",
"\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js"
},
"testPathIgnorePatterns": [
"<rootDir>/node_modules/",
"<rootDir>/legacy_notes_and_workbook/",
"<rootDir>/src/stylesheets/"
],
"transform": {},
"transformIgnorePatterns": [ "<roodDir>/node_modules/(?!)" , "node_modules/(?!(jest-)?react-native|react-navigation)" ],
"testRegex": "(/__tests__/.*|\\.?(test|spec|Test|Spec))\\.(ts|tsx|js|jsx)$"
}
我机器上安装的节点版本是: 节点-v v4.2.2
npm -v 1.4.28
如果有人对上述问题有任何解决方案,请告诉我。提前谢谢。