-
Notifications
You must be signed in to change notification settings - Fork 361
Expand file tree
/
Copy pathlcov.js
More file actions
55 lines (42 loc) · 1.4 KB
/
lcov.js
File metadata and controls
55 lines (42 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* Module dependencies
*/
var nodeunit = require('../nodeunit'),
path = require('path');
/**
* Reporter info string
*/
exports.info = 'The LCOV reporter reads JS files instrumented by JSCoverage (http://siliconforks.com/jscoverage/) and outputs coverage data in the LCOV format (http://ltp.sourceforge.net/coverage/lcov/geninfo.1.php)';
/**
* Run all tests within each module, reporting the results to the command-line.
*
* @param {Array} files
* @api public
*/
exports.run = function (files, options, callback) {
var paths = files.map(function (p) {
return path.resolve(p);
});
nodeunit.runFiles(paths, {
recursive: options.recursive,
done: function (assertions) {
var cov = (global || window)._$jscoverage || {};
Object.keys(cov).forEach(function (filename) {
var data = cov[filename];
reportFile(filename, data);
});
if (callback) callback(assertions.failures() ? new Error('We have got test failures.') : undefined);
}
});
};
function reportFile(filename, data) {
console.log('SF:' + filename);
data.source.forEach(function(line, num) {
// increase the line number, as JS arrays are zero-based
num++;
if (data[num] !== undefined) {
console.log('DA:' + num + ',' + data[num]);
}
});
console.log('end_of_record');
}