1 |
|
/* |
2 |
|
Copyright (c) 2012, Yahoo! Inc. All rights reserved. |
3 |
|
Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms. |
4 |
|
*/ |
5 |
|
|
6 |
1 |
var path = require('path'), |
7 |
|
fs = require('fs'), |
8 |
|
util = require('util'), |
9 |
|
Report = require('./index'), |
10 |
|
Store = require('../store'), |
11 |
|
Writer = require('../util/file-writer'), |
12 |
|
utils = require('../object-utils'); |
13 |
|
|
14 |
|
/** |
15 |
|
* a `Report` implementation that produces an LCOV coverage file from coverage objects. |
16 |
|
* |
17 |
|
* Usage |
18 |
|
* ----- |
19 |
|
* |
20 |
|
* var report = require('istanbul').Report.create('lcovonly'); |
21 |
|
* |
22 |
|
* |
23 |
|
* @class LcovOnlyReport |
24 |
|
* @extends Report |
25 |
|
* @constructor |
26 |
|
* @param {Object} opts optional |
27 |
|
* @param {String} [opts.dir] the directory in which to the `lcov.info` file. Defaults to `process.cwd()` |
28 |
|
*/ |
29 |
1 |
function LcovOnlyReport(opts) { |
30 |
4 |
this.opts = opts || {}; |
31 |
4 |
this.opts.dir = this.opts.dir || process.cwd(); |
32 |
|
} |
33 |
1 |
LcovOnlyReport.TYPE = 'lcovonly'; |
34 |
1 |
util.inherits(LcovOnlyReport, Report); |
35 |
|
|
36 |
1 |
Report.mix(LcovOnlyReport, { |
37 |
|
writeFileCoverage: function (writer, fc) { |
38 |
16 |
var functions = fc.f, |
39 |
|
functionMap = fc.fnMap, |
40 |
|
lines = fc.l, |
41 |
|
branches = fc.b, |
42 |
|
branchMap = fc.branchMap; |
43 |
|
|
44 |
16 |
writer.println('TN:'); //no test name |
45 |
16 |
writer.println('SF:' + fc.path); |
46 |
|
|
47 |
16 |
Object.keys(functions).forEach(function (key) { |
48 |
20 |
var meta = functionMap[key]; |
49 |
20 |
writer.println('FN:' + [ meta.line, meta.name ].join(',')); |
50 |
|
}); |
51 |
|
|
52 |
16 |
Object.keys(functions).forEach(function (key) { |
53 |
20 |
var stats = functions[key], |
54 |
|
meta = functionMap[key]; |
55 |
20 |
writer.println('FNDA:' + [ stats, meta.name ].join(',')); |
56 |
|
}); |
57 |
|
|
58 |
16 |
Object.keys(lines).forEach(function (key) { |
59 |
56 |
var stat = lines[key]; |
60 |
56 |
writer.println('DA:' + [ key, stat ].join(',')); |
61 |
|
}); |
62 |
|
|
63 |
16 |
Object.keys(branches).forEach(function (key) { |
64 |
12 |
var branchArray = branches[key], |
65 |
|
meta = branchMap[key], |
66 |
|
line = meta.line, |
67 |
|
i = 0; |
68 |
12 |
branchArray.forEach(function (b) { |
69 |
24 |
writer.println('BRDA:' + [line, key, i, b].join(',')); |
70 |
24 |
i += 1; |
71 |
|
}); |
72 |
|
}); |
73 |
16 |
writer.println('end_of_record'); |
74 |
|
}, |
75 |
|
|
76 |
|
writeReport: function (collector, sync) { |
77 |
4 |
var outputFile = path.resolve(this.opts.dir, 'lcov.info'), |
78 |
|
writer = new Writer(sync), |
79 |
|
that = this; |
80 |
4 |
writer.start(outputFile); |
81 |
4 |
collector.files().forEach(function (key) { |
82 |
16 |
that.writeFileCoverage(writer, collector.fileCoverageFor(key)); |
83 |
|
}); |
84 |
4 |
writer.end(); |
85 |
|
} |
86 |
|
}); |
87 |
|
|
88 |
1 |
module.exports = LcovOnlyReport; |