UNPKG

1.41 kBJavaScriptView Raw
1/**
2 * Module dependencies
3 */
4
5var nodeunit = require('../nodeunit'),
6 path = require('path');
7
8/**
9 * Reporter info string
10 */
11
12exports.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)';
13
14/**
15 * Run all tests within each module, reporting the results to the command-line.
16 *
17 * @param {Array} files
18 * @api public
19 */
20
21exports.run = function (files, options, callback) {
22
23 var paths = files.map(function (p) {
24 return path.resolve(p);
25 });
26
27 nodeunit.runFiles(paths, {
28 done: function (assertions) {
29 var cov = (global || window)._$jscoverage || {};
30
31 Object.keys(cov).forEach(function (filename) {
32 var data = cov[filename];
33 reportFile(filename, data);
34 });
35
36 if (callback) callback(assertions.failures() ? new Error('We have got test failures.') : undefined);
37 }
38 });
39};
40
41function reportFile(filename, data) {
42 console.log('SF:' + filename);
43
44 data.source.forEach(function(line, num) {
45 // increase the line number, as JS arrays are zero-based
46 num++;
47
48 if (data[num] !== undefined) {
49 console.log('DA:' + num + ',' + data[num]);
50 }
51 });
52
53 console.log('end_of_record');
54}