我尝试设置npm
以使用istanbul
检查覆盖范围。以下是package.json
的脚本:
"scripts": {
"coverage:report": "istanbul cover _mocha --",
"coverage:check": "istanbul check-coverage",
"test": "./node_modules/.bin/mocha test/hooks.js test/**/*.spec.js",
}
我也是这两个配置文件:
.istanbul.yml
instrumentation:
root: app
check:
global:
statements: 100
lines: 100
branches: 100
functions: 100
mocha.opts
--reporter spec
--ui bdd
--recursive
--colors
当我运行npm run coverage:report
时,我得到以下输出:
=============================== Coverage summary ===============================
Statements : 98.69% ( 301/305 )
Branches : 95.08% ( 58/61 )
Functions : 100% ( 22/22 )
Lines : 98.65% ( 293/297 )
================================================================================
所以npm run coverage:check
应该失败,但事实并非如此。这是我得到的输出
npm run coverage:check
> ...@2.0.0 coverage:check /home/.../.../...-v2-server
> istanbul check-coverage
我错过了什么?
答案 0 :(得分:0)
我仍然不知道为什么它不起作用,但我切换到nyc
并且它正在使用以下配置
<强> .nycrc 强>
{
"reporter": [
"lcov",
"text-summary"
],
"include": [
"app/**/*.js",
"test/utils/**/*.js",
"test/fixtures/**/*.js"
],
"exclude": [
"test/**/*.spec.js"
],
"lines": 100,
"statements": 100,
"functions": 100,
"branches": 100,
"check-coverage": true
}
<强>测试/ mocha.opts 强>
--reporter spec
--ui bdd
--recursive
--colors
<强>的package.json 强>
"scripts": {
"lint": "./node_modules/.bin/eslint *.js --cache",
"lint:fix": "npm run lint -- --fix"
"start": "node -e 'require(\"./app\").start()' | bunyan",
"test": "nyc ./node_modules/.bin/mocha test/hooks.js test/**/*.spec.js"
},