使用Jest和Enzyme运行一些针对react js的测试,但是其中一个文件不断损坏。使用笑话和酶
我已经清除了缓存,但是我不断得到以下内容:
NPM错误!测试失败 并且工作进程意外退出!这很可能是初始化错误
这是package.json的一部分。 不太确定如何解决此问题。
scripts": {
"start": "node scripts/start.js",
"start-3001": "set PORT=3001&& node scripts/start.js",
"start-3002": "set PORT=3002&& node scripts/start.js",
"build": "node scripts/build.js",
"test": "node scripts/test.js --env=jsdom --verbose || exit 0"
},
"devDependencies": {
"enzyme-to-json": "^3.3.5",
"jes": "^0.6.1",
"jest": "^20.0.4",
"jest-fetch-mock": "^2.1.2",
"react-addons-test-utils": "^15.6.2",
"react-dom": "^15.6.2",
"react-test-renderer": "^15.5.4"
},
"jest": {
"automock": false,
"collectCoverageFrom": [
"src/**/*.{js,jsx}"
],
"setupFiles": [
"<rootDir>/config/polyfills.js"
],
"testMatch": [
"<rootDir>/src/**/__tests__/**/*.js?(x)",
"<rootDir>/src/**/?(*.)(spec|test).js?(x)"
],
"testEnvironment": "node",
"verbose": true,
"testURL": "http://localhost:3000",
"transform": {
"^.+\\.(js|jsx)$": "<rootDir>/node_modules/babel-jest",
"^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
"^(?!.*\\.(js|jsx|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
},
"transformIgnorePatterns": [
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$"
],
"moduleNameMapper": {
"^react-native$": "react-native-web"
},
"moduleFileExtensions": [
"web.js",
"js",
"json",
"web.jsx",
"jsx",
"node"
]
},
"babel": {
"presets": [
"react-app",
"stage-0"
]
},
"eslintConfig": {
"extends": "react-app"
}
}
答案 0 :(得分:1)
删除node_modules和package-lock.json或yarn.lock文件。再次运行npm install,看看是否能解决问题。