当在游戏中并行运行时,测试过程终止 - “工作进程意外退出!”

时间:2017-03-10 23:52:26

标签: javascript node.js jest

我在开玩笑中并行跑步时测试失败。

当我尝试并运行时

jest 

从我的项目根目录中,我收到以下错误,测试过程终止。

“工人进程意外退出!”

我正在使用jest 19.0.2和节点6.9.4。我还尝试过节点7.7.2和jest 19.0的其他组合,这两种组合都不起作用。

enter image description here

请注意,当我使用

顺序运行测试时
jest --runInBand

我的测试工作正常。虽然由于它们没有并行运行,但速度较慢,这并不理想。

我的测试为每个新测试启动相同的服务器,因此可能并行运行意味着多个测试试图在已经运行的端口上启动服务器。

enter image description here

这是我的package.json:

{
  "name": "app",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "autoprefixer": "6.5.1",
    "babel-core": "6.17.0",
    "babel-eslint": "7.1.1",
    "babel-jest": "17.0.2",
    "babel-loader": "6.2.7",
    "babel-preset-react-app": "^2.0.1",
    "case-sensitive-paths-webpack-plugin": "1.1.4",
    "chai": "^3.5.0",
    "chai-as-promised": "^6.0.0",
    "chalk": "1.1.3",
    "connect-history-api-fallback": "1.3.0",
    "cross-spawn": "4.0.2",
    "css-loader": "0.26.0",
    "detect-port": "1.0.1",
    "dotenv": "2.0.0",
    "eslint": "3.8.1",
    "eslint-config-react-app": "^0.5.0",
    "eslint-loader": "1.6.0",
    "eslint-plugin-flowtype": "2.21.0",
    "eslint-plugin-import": "2.0.1",
    "eslint-plugin-jsx-a11y": "2.2.3",
    "eslint-plugin-react": "6.4.1",
    "extract-text-webpack-plugin": "1.0.1",
    "file-loader": "0.9.0",
    "filesize": "3.3.0",
    "fs-extra": "0.30.0",
    "gzip-size": "3.0.0",
    "html-webpack-plugin": "2.24.0",
    "http-proxy-middleware": "0.17.2",
    "jest": "^19.0.2",
    "jest-css-modules": "^1.1.0",
    "json-loader": "0.5.4",
    "object-assign": "4.1.0",
    "path-exists": "2.1.0",
    "postcss-loader": "1.0.0",
    "promise": "7.1.1",
    "react-dev-utils": "^0.4.2",
    "recursive-readdir": "2.1.0",
    "redux-mock-store": "^1.2.2",
    "sinon": "^1.17.7",
    "strip-ansi": "3.0.1",
    "style-loader": "0.13.1",
    "supertest": "^3.0.0",
    "url-loader": "0.5.7",
    "webpack": "1.14.0",
    "webpack-dev-server": "1.16.2",
    "webpack-manifest-plugin": "1.1.0",
    "whatwg-fetch": "1.0.0"
  },
  "dependencies": {
    "axios": "^0.15.3",
    "bcrypt-nodejs": "0.0.3",
    "body-parser": "^1.16.0",
    "cors": "^2.8.1",
    "eventemitter2": "^3.0.1",
    "express": "^4.14.0",
    "jwt-simple": "^0.5.1",
    "mocha": "^3.2.0",
    "mongoose": "^4.7.8",
    "morgan": "^1.7.0",
    "nodemon": "^1.11.0",
    "passport": "^0.3.2",
    "passport-jwt": "^2.2.1",
    "passport-local": "^1.0.0",
    "react": "^15.4.2",
    "react-dom": "^15.4.2",
    "react-redux": "^5.0.2",
    "react-router": "^3.0.2",
    "redux": "^3.6.0",
    "redux-devtools-extension": "^2.13.0",
    "redux-form": "^5.3.3",
    "redux-socket.io": "^1.3.1",
    "redux-thunk": "^2.2.0",
    "socket.io-client": "^1.7.3",
    "socketio-auth": "^0.1.0"
  },
  "scripts": {
    "start": "node scripts/start.js",
    "build": "node scripts/build.js",
    "test": "jest --runInBand"
  },
  "jest": {
    "collectCoverageFrom": [
      "src/**/*.{js,jsx}"
    ],
    "setupFiles": [
      "<rootDir>/config/polyfills.js"
    ],
    "testPathIgnorePatterns": [
      "<rootDir>[/\\\\](build|docs|node_modules)[/\\\\]"
    ],
    "testEnvironment": "jest-environment-jsdom",
    "testURL": "http://localhost",
    "transform": {
      "^.+\\.(js|jsx)$": "<rootDir>/node_modules/babel-jest",
      "^.+\\.css$": "<rootDir>/node_modules/jest-css-modules"
    },
    "transformIgnorePatterns": [
      "[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$"
    ],
    "verbose": true,
    "moduleNameMapper": {
      "^react-native$": "react-native-web"
    }
  },
  "babel": {
    "presets": [
      "react-app"
    ]
  },
  "eslintConfig": {
    "extends": "react-app"
  }
}

1 个答案:

答案 0 :(得分:1)

尝试将此标志添加到jest CLI命令:

jest --env=jsdom --runInBand
来自Jest API文档的

http://facebook.github.io/jest/docs/cli.html#env-environment