gpt4 book ai didi

javascript - 使用 Karma/Istanbul 设置目标代码覆盖率

转载 作者:行者123 更新时间:2023-11-29 21:46:27 26 4
gpt4 key购买 nike

我正在使用 Karma-Coverage(Istanbul) 运行 Karma Maven 插件以实现代码覆盖率。对于所需(建议?)代码覆盖率, karma 覆盖率似乎默认为 80%,但是我想在项目中强制执行 90% 的代码覆盖率。但是,我不知道在哪里设置它。

有没有办法通过 Karma/Istanbul 强制执行目标代码覆盖率?

最佳答案

这记录在 docs file in the repo. 中查找有关“check”属性的部分。

This will be used to configure minimum threshold enforcement for coverage results. If the thresholds are not met, karma will return failure. Thresholds, when specified as a positive number are taken to be the minimum percentage required. When a threshold is specified as a negative number it represents the maximum number of uncovered entities allowed.

For example, statements: 90 implies minimum statement coverage is 90%. statements: -10 implies that no more than 10 uncovered statements are allowed.

global applies to all files together and each on a per-file basis. A list of files or patterns can be excluded from enforcement via the exclude property. On a per-file or pattern basis, per-file thresholds can be overridden via the overrides property.

coverageReporter: {
check: {
global: {
statements: 50,
branches: 50,
functions: 50,
lines: 50,
excludes: [
'foo/bar/**/*.js'
]
},
each: {
statements: 50,
branches: 50,
functions: 50,
lines: 50,
excludes: [
'other/directory/**/*.js'
],
overrides: {
'baz/component/**/*.js': {
statements: 98
}
}
}
}
}

如果您查看@MarcoCI 引用的代码,您会发现 karma 正在执行相当标准的选项合并,这意味着您不必重新创建整个检查对象。只是您关心的值。默认值为 0。

关于javascript - 使用 Karma/Istanbul 设置目标代码覆盖率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31030946/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com