我找到了lcov解析工具来解析lcov信息文件。我怎么能用呢。在这个链接中解释的用法:https://github.com/davglass/lcov-parse/blob/master/README.md不清楚。我需要知道在哪里可以使用代码来解析和提取信息。
发布于 2018-03-01 15:26:53
使用部分中描述的README.md链接中描述的代码说明了如何在javascript中调用该工具(我添加了额外的注释):
// Include the lcov-parse dependency, installed via npm
var parse = require('lcov-parse');
// Specify the path to the file to parse,
// the file contents are parsed into a JSON object, "data"
parse('./path/to/file.info', function(err, data) {
// process the data here
// e.g. write out to a string
});要在命令行上运行和输出,Cli使用部分中的描述对我无效,但是在bin目录下的项目的github页面中可以看到一个可执行代码的示例:
https://github.com/davglass/lcov-parse/blob/master/bin/cli.js
该文件的内容如下:
#!/usr/bin/env node
var lcov = require('../lib/index.js');
var file = process.argv[2];
lcov(file, function(err, data) {
if (err) {
return console.error(err)
}
console.log(JSON.stringify(data));
});同样,这里的data是解析为JSON对象的lcov文件。
运行它的:
1)首先使用npm安装lcov解析工具:
npm install lcov-parse在一个空目录中,这将创建几个文件,其中一个是上面用于在命令行上运行该工具的javascript示例:
./node_modules/lcov-parse/bin/cli.js
2)脚本可以这样运行:
./node_modules/lcov-parse/bin/cli.js ./path/to/lcovfile例如,在lcov的覆盖率文件上测试它-解析:
./node_modules/lcov-parse/bin/cli.js ./node_modules/lcov-parse/coverage/lcov.info3) JSON.stringify的默认格式很难用眼睛读取,可以通过添加一个间距参数(例如两个空格)来改进:
console.log(JSON.stringify(data, null, 2));https://stackoverflow.com/questions/43205673
复制相似问题