javascript - 如何将现有的 Istanbul 尔 json 文件转换为 html

标签 javascript code-coverage istanbul remap-istanbul

我想将从客户端获取的 JSON 格式的 istanbul 覆盖率报告文件转换为 html 格式。目前我正在为此使用 remap-istanbul 但实际上那个特定的特定工具旨在重新映射最初用不同语言(如 typescript )编写的代码的覆盖率数据。

所以我想是否有更方便的方法来做同样的事情

最佳答案

使用 istanbul report html 将现有的覆盖率数据从 JSON 转换为 HTML:

istanbul report html

默认情况下,上面的代码会在当前目录(及其子目录)中查找任何以“coverage”开头并以“.json”结尾的文件,并将 HTML 报告输出到 ./coverage/目录。

将特定文件转换为特定目录:

istanbul report --include path/to/my-coverage-file.json --dir my-coverage-dir html

另一种仅从特定目录(例如 path/to 中的所有 JSON 文件)读取覆盖率报告的方法如下,使用 --root 选项:

istanbul report --root path/to --include=*.json --dir my-coverage-dir html

使用istanbul help report查看更多选项(以下是用istanbul 0.4.5生成的):

Usage: istanbul report <options> [ <format> ... ]

Options are:

      --config <path-to-config>
              the configuration file to use, defaults to .istanbul.yml

      --root <input-directory>
              The input root directory for finding coverage files

      --dir <report-directory>
              The output directory where files will be written. This defaults
              to ./coverage/

      --include <glob>
              The glob pattern to select one or more coverage files, defaults
              to **/coverage*.json

      --verbose, -v
              verbose mode


<format> is one of 
      clover  XML coverage report that can be consumed by the clover tool
      cobertura
              XML coverage report that can be consumed by the cobertura tool
      html    Navigable HTML coverage report for every file and directory
      json    prints the coverage object as JSON to a file
      json-summary
              prints a summary coverage object as JSON to a file
      lcov    combined lcovonly and html report that generates an lcov.info
              file as well as HTML
      lcovonly
              lcov coverage report that can be consumed by the lcov tool
      none    Does nothing. Useful to override default behavior and suppress
              reporting entirely
      teamcity
              report with system messages that can be interpreted with TeamCity
      text    text report that prints a coverage line for every file, typically
              to console
      text-lcov
              lcov coverage report that can be consumed by the lcov tool
      text-summary
              text report that prints a coverage summary across all files,
              typically to console

 Default format is lcov unless otherwise specified in the config file. In
 addition you can tweak the file names for various reports using the config
 file. Type `istanbul help config` to see what can be tweaked.

--input 的值是一个 glob 模式。有关 glob 模式的更多文档,请参阅 documentation at the glob package on NPM .

关于javascript - 如何将现有的 Istanbul 尔 json 文件转换为 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46709413/

相关文章:

javascript - MongoDB,如果新值不为空,则更新集合字段

JavaScript - 如何在回调函数之外使用 FB.Canvas.getPageInfo 的高度

javascript - 为什么我的 "valid"JS 代码不起作用?

node.js - 使用 Istanbul 对 Node 微服务进行集成测试

javascript - 查找调用函数的文件的位置(nodejs)

azure-devops - 提供 .runsettings 文件时,VSTS 中没有代码覆盖率

PhpUnit 忽略了它的 XML 配置文件中的*一些*指令

c - 如何做gcc编译器的源代码覆盖

node.js - 如何忽略与 Istanbul 尔的 promise 的所有失败案例