4

我写了一些放在文件夹 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 的引用。

谢谢你的帮助。

4

1 回答 1

0

使用这样的nyc 配置文件(从这里):

{
  "all": true,
  "include": [
    "src/**/*.js"
  ],
  "exclude": [
    "**/*.spec.js"
  ]
}
于 2021-01-25T12:22:02.263 回答