【问题标题】:Mocha, nyc code coverage - only testing files are coveredMocha, nyc 代码覆盖率 - 仅覆盖测试文件
【发布时间】:2018-05-21 14:02:56
【问题描述】:

我写了一些测试放在文件夹test中。

问题:使用 nyc 的代码覆盖率显示只有 CC 用于测试文件。 希望:src 中的所有文件都以百分比显示在 CC 中,即使它们尚未经过测试。

我的包 json 和脚本:

"scripts": {
    "start": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js",
    "test": "mocha --compilers js:babel-core/register --require ./test/testing_helper.js ./test/**/*.js",
    "test:watch": "npm run test -- --watch",
    "code:coverage": "nyc npm run test"
  },
  "author": "",
  "license": "",
  "devDependencies": {
    "babel-core": "^6.2.1",
    "babel-loader": "^6.2.0",
    "babel-preset-es2015": "^6.1.18",
    "babel-preset-react": "^6.1.18",
    "chai": "^3.5.0",
    "chai-jquery": "^2.0.0",
    "expect": "^21.2.1",
    "jquery": "^2.2.1",
    "jsdom": "^8.1.0",
    "mocha": "^2.4.5",
    "nyc": "^11.3.0",
    "react-addons-test-utils": "^0.14.7",
    "webpack": "^1.12.9",
    "webpack-dev-server": "^1.14.0"
  },
  "dependencies": {
    "babel-preset-stage-1": "^6.1.18",
    "lodash": "^3.10.1",
    "react": "^0.14.3",
    "react-dom": "^0.14.3",
    "react-redux": "4.3.0",
    "react-router": "^2.0.1",
    "redux": "^3.0.4",
    "redux-devtools-extension": "^2.13.2"
  }
例如,

testing_helper.js 有很多导入。 jsdom,所以每当我尝试 为 nyc 制作一个带有配置的脚本包括: testing_helper.js 它总是说:

意外的导入令牌 -> 和对 jsdom 的引用。

感谢您的帮助。

【问题讨论】:

    标签: testing mocha.js nyc


    【解决方案1】:

    像这样使用nyc configuration file(来自here):

    {
      "all": true,
      "include": [
        "src/**/*.js"
      ],
      "exclude": [
        "**/*.spec.js"
      ]
    }
    

    【讨论】:

      猜你喜欢
      • 2023-04-07
      • 2013-05-14
      • 2018-10-09
      • 2020-09-10
      • 2012-01-18
      • 1970-01-01
      • 2015-08-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多