2017-04-04 57 views

回答

0

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使用部分的描述并没有为我工作,但可执行代码的例子可以在项目的GitHub上页下的bin目录中可以看出:

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.info 

3)的JSON.stringify的默认格式是很难通过肉眼阅读,它可以通过添加间隔参数(例如2位)而得到提高:

console.log(JSON.stringify(data, null, 2));