【问题标题】:Istanbul check-coverage always return true伊斯坦布尔检查覆盖率始终返回 true
【发布时间】:2016-10-31 16:11:49
【问题描述】:

我正在尝试设置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

我错过了什么?

【问题讨论】:

  • 您可以尝试将yml 文件中的节点check - global 替换为thresholds 吗?
  • 问题依旧

标签: node.js mocha.js code-coverage istanbul


【解决方案1】:

我仍然不明白为什么它不起作用,但我切换到 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
}

test/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"
},

【讨论】:

  • 如何设置每个文件的覆盖范围限制,即默认覆盖范围检查是针对全局覆盖范围进行的,如何为每个类似于 Istanbul.ymls 的文件设置
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-07-02
  • 1970-01-01
  • 2015-08-26
  • 2019-04-28
  • 2015-07-29
  • 2015-09-10
  • 2013-12-21
相关资源
最近更新 更多