无法使用JEST获得反应的测试覆盖率

时间:2016-08-29 15:58:50

标签: reactjs jestjs istanbul

我正在尝试为反应代码运行JEST,它总是显示PASS并且没有运行任何编写在test folder.Inside coverage文件夹中的脚本我也没有得到任何组件文件夹被创建。请让我知道如何修复它

以下是我的配置

的package.json

{
  "devDependencies": {
  "axios": "^0.11.1",
    "babel": "^6.5.2",
    "babel-core": "^6.7.4",
    "babel-eslint": "^4.1.6",
    "babel-jest": "^9.0.3",
    "babel-loader": "^6.2.4",
    "babel-plugin-transform-runtime": "^6.6.0",
    "babel-polyfill": "^6.3.14",
    "babel-preset-es2015": "^6.6.0",
    "babel-preset-react": "^6.5.0",
    "bower-webpack-plugin": "^0.1.9",
    "css-loader": "^0.23.1",
    "es6-promise": "^3.2.1",
    "es6bindall": "0.0.5",
    "eslint": "^1.10.3",
    "eslint-loader": "^1.0.0",
    "eslint-plugin-react": "^5.0.0",
    "express": "^4.13.4",
    "extract-text-webpack-plugin": "^1.0.1",
    "file-loader": "^0.8.4",
    "grunt": "^1.0.1",
    "grunt-cli": "^1.2.0",
    "grunt-jest": "^0.2.0",
    "grunt-webpack": "^1.0.11",
    "imports-loader": "^0.6.5",
    "jasmine-ajax": "^3.2.0",
    "jest-cli": "^0.9.2",
    "node-sass": "^3.4.2",
     "react": "^15.0.0",
    "react-dom": "^15.0.0",
    "react-fileupload": "^2.2.0",
    "react-hot-loader": "^1.2.9",
    "react-router": "^2.6.1",
    "sass-loader": "^3.2.0",
    "sinon": "^1.17.4",
    "style-loader": "^0.13.1",
    "webpack": "^1.12.14",
    "webpack-dev-server": "^1.14.1"
  },
  "scripts": {
    "prestart": "webpack",
    "build": "webpack",
    "test": "jest",
    "lint": "node_modules/.bin/eslint -f html app-client.js components > report.html || exit 0",
    "start": "node app-server.js"
  },
   "jest": {
    "scriptPreprocessor": "<rootDir>/jest-script-preprocessor",
    "collectCoverage": true,
    "preprocessorIgnorePatterns": [
      "../frontend/node_modules/"
    ],
    "testFileExtensions": [
      "js",
      "es6"
    ],
    "moduleFileExtensions": [
      "js",
      "json",
      "es6"
    ],
    "unmockedModulePathPatterns": [ 
      "react",
      "fbjs",
      "react-dom",
      "react-addons-test-utils",
      "es6bindall",
      "axios",
      "promise",
      "react-router",
      "sinon"
    ],
    "verbose": true 
  }
}

1 个答案:

答案 0 :(得分:0)

测试文件夹应为__tests__而不是tests。如果要更改,则需要使用testRegex选项。

如果你想用覆盖率运行它,你可以这样做:

jest --coverage

或在您的脚本案例中:

npm test -- --coverage

请注意,我在谈论最新版本的Jest(14.x)。你可以找到一篇关于设置Jest并运行或不运行测试的example