Javascript 如何配置伊斯坦布尔覆盖率报告以排除某些来源?
我正在开发一个nodeJS+角度堆叠应用程序。为了生成后端的代码覆盖率报告,我使用了伊斯坦布尔和摩卡。然而,报道显示的数字不正确 如果我运行Javascript 如何配置伊斯坦布尔覆盖率报告以排除某些来源?,javascript,node.js,mocha.js,istanbul,Javascript,Node.js,Mocha.js,Istanbul,我正在开发一个nodeJS+角度堆叠应用程序。为了生成后端的代码覆盖率报告,我使用了伊斯坦布尔和摩卡。然而,报道显示的数字不正确 如果我运行istanbul cover\u mocha--print detail/path/to/tests*我会得到完整的覆盖范围(但仅限于测试规范要求的文件)。另一方面,如果我运行istanbul cover\u mocha——打印详细信息——包括所有源代码/路径/到/测试*istanbul也会检查前端代码的测试覆盖率(angular,我分别使用karma/ja
istanbul cover\u mocha--print detail/path/to/tests*
我会得到完整的覆盖范围(但仅限于测试规范要求的文件)。另一方面,如果我运行istanbul cover\u mocha——打印详细信息——包括所有源代码/路径/到/测试*
istanbul也会检查前端代码的测试覆盖率(angular,我分别使用karma/jasmine进行测试)
如何运行伊斯坦布尔,使其只包含后端源文件?您的后端代码和前端代码是否在不同的目录中?例如
/test/api
和/test/dashboard
等等。如果您将代码分开,您可以告诉伊斯坦布尔在这样的时间报告每个代码:
伊斯坦布尔封面_mochatest/api/***.js
有道理吗?那对你有用吗
让我知道。我也遇到过类似的情况,因此我认为如果它可以帮助别人,尽管这是一篇老文章,还是值得分享的伊斯坦布尔在运行命令时将当前目录(..作为覆盖目录。为了只包含覆盖范围的特定目录,请使用
“--root/dir/”
选项。这将仅为该目录中的文件生成覆盖率报告。根据伊斯坦布尔帮助覆盖率输出
$ ./node_modules/.bin/istanbul help cover
Usage: istanbul cover [<options>] <executable-js-file-or-command> [--<arguments-to-jsfile>]
Options are:
--config <path-to-config>
the configuration file to use, defaults to .istanbul.yml
--root <path>
the root path to look for files to instrument, defaults to .
-x <exclude-pattern> [-x <exclude-pattern>]
one or more glob patterns e.g. "**/vendor/**"
-i <include-pattern> [-i <include-pattern>]
one or more glob patterns e.g. "**/*.js"
--[no-]default-excludes
apply default excludes [ **/node_modules/**, **/test/**,
**/tests/** ], defaults to true
--hook-run-in-context
hook vm.runInThisContext in addition to require (supports
RequireJS), defaults to false
--post-require-hook <file> | <module>
JS module that exports a function for post-require processing
--report <format> [--report <format>]
report format, defaults to lcov (= lcov.info + HTML)
--dir <report-dir>
report directory, defaults to ./coverage
--print <type>
type of report to print to console, one of summary (default),
detail, both or none
--verbose, -v
verbose mode
--[no-]preserve-comments
remove / preserve comments in the output, defaults to false
--include-all-sources
instrument all unused sources after running tests, defaults to
false
--[no-]include-pid
include PID in output coverage filename
将执行测试,并忽略覆盖率报告上的dist/index.js文件我项目的结构更像
server/*public/js*(angular)test/mocha/*(backend tests)test/jasmine/*(angular tests)
$ ./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha test -X dist/index.js