1 | /*
|
---|
2 | Copyright 2012-2015, Yahoo Inc.
|
---|
3 | Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
|
---|
4 | */
|
---|
5 | 'use strict';
|
---|
6 | const { ReportBase } = require('istanbul-lib-report');
|
---|
7 |
|
---|
8 | class LcovOnlyReport extends ReportBase {
|
---|
9 | constructor(opts) {
|
---|
10 | super();
|
---|
11 | this.file = opts.file || 'lcov.info';
|
---|
12 | this.projectRoot = opts.projectRoot || process.cwd();
|
---|
13 | this.contentWriter = null;
|
---|
14 | }
|
---|
15 |
|
---|
16 | onStart(root, context) {
|
---|
17 | this.contentWriter = context.writer.writeFile(this.file);
|
---|
18 | }
|
---|
19 |
|
---|
20 | onDetail(node) {
|
---|
21 | const fc = node.getFileCoverage();
|
---|
22 | const writer = this.contentWriter;
|
---|
23 | const functions = fc.f;
|
---|
24 | const functionMap = fc.fnMap;
|
---|
25 | const lines = fc.getLineCoverage();
|
---|
26 | const branches = fc.b;
|
---|
27 | const branchMap = fc.branchMap;
|
---|
28 | const summary = node.getCoverageSummary();
|
---|
29 | const path = require('path');
|
---|
30 |
|
---|
31 | writer.println('TN:'); //no test nam
|
---|
32 | const fileName = path.relative(this.projectRoot, fc.path);
|
---|
33 | writer.println('SF:' + fileName);
|
---|
34 |
|
---|
35 | Object.values(functionMap).forEach(meta => {
|
---|
36 | writer.println('FN:' + [meta.decl.start.line, meta.name].join(','));
|
---|
37 | });
|
---|
38 | writer.println('FNF:' + summary.functions.total);
|
---|
39 | writer.println('FNH:' + summary.functions.covered);
|
---|
40 |
|
---|
41 | Object.entries(functionMap).forEach(([key, meta]) => {
|
---|
42 | const stats = functions[key];
|
---|
43 | writer.println('FNDA:' + [stats, meta.name].join(','));
|
---|
44 | });
|
---|
45 |
|
---|
46 | Object.entries(lines).forEach(entry => {
|
---|
47 | writer.println('DA:' + entry.join(','));
|
---|
48 | });
|
---|
49 | writer.println('LF:' + summary.lines.total);
|
---|
50 | writer.println('LH:' + summary.lines.covered);
|
---|
51 |
|
---|
52 | Object.entries(branches).forEach(([key, branchArray]) => {
|
---|
53 | const meta = branchMap[key];
|
---|
54 | if (meta) {
|
---|
55 | const { line } = meta.loc.start;
|
---|
56 | branchArray.forEach((b, i) => {
|
---|
57 | writer.println('BRDA:' + [line, key, i, b].join(','));
|
---|
58 | });
|
---|
59 | } else {
|
---|
60 | console.warn('Missing coverage entries in', fileName, key);
|
---|
61 | }
|
---|
62 | });
|
---|
63 | writer.println('BRF:' + summary.branches.total);
|
---|
64 | writer.println('BRH:' + summary.branches.covered);
|
---|
65 | writer.println('end_of_record');
|
---|
66 | }
|
---|
67 |
|
---|
68 | onEnd() {
|
---|
69 | this.contentWriter.close();
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | module.exports = LcovOnlyReport;
|
---|