| 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 | opts = opts || {};
|
|---|
| 12 | this.file = opts.file || 'lcov.info';
|
|---|
| 13 | this.projectRoot = opts.projectRoot || process.cwd();
|
|---|
| 14 | this.contentWriter = null;
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | onStart(root, context) {
|
|---|
| 18 | this.contentWriter = context.writer.writeFile(this.file);
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | onDetail(node) {
|
|---|
| 22 | const fc = node.getFileCoverage();
|
|---|
| 23 | const writer = this.contentWriter;
|
|---|
| 24 | const functions = fc.f;
|
|---|
| 25 | const functionMap = fc.fnMap;
|
|---|
| 26 | const lines = fc.getLineCoverage();
|
|---|
| 27 | const branches = fc.b;
|
|---|
| 28 | const branchMap = fc.branchMap;
|
|---|
| 29 | const summary = node.getCoverageSummary();
|
|---|
| 30 | const path = require('path');
|
|---|
| 31 |
|
|---|
| 32 | writer.println('TN:');
|
|---|
| 33 | const fileName = path.relative(this.projectRoot, fc.path);
|
|---|
| 34 | writer.println('SF:' + fileName);
|
|---|
| 35 |
|
|---|
| 36 | Object.values(functionMap).forEach(meta => {
|
|---|
| 37 | // Some versions of the instrumenter in the wild populate 'loc'
|
|---|
| 38 | // but not 'decl':
|
|---|
| 39 | const decl = meta.decl || meta.loc;
|
|---|
| 40 | writer.println('FN:' + [decl.start.line, meta.name].join(','));
|
|---|
| 41 | });
|
|---|
| 42 | writer.println('FNF:' + summary.functions.total);
|
|---|
| 43 | writer.println('FNH:' + summary.functions.covered);
|
|---|
| 44 |
|
|---|
| 45 | Object.entries(functionMap).forEach(([key, meta]) => {
|
|---|
| 46 | const stats = functions[key];
|
|---|
| 47 | writer.println('FNDA:' + [stats, meta.name].join(','));
|
|---|
| 48 | });
|
|---|
| 49 |
|
|---|
| 50 | Object.entries(lines).forEach(entry => {
|
|---|
| 51 | writer.println('DA:' + entry.join(','));
|
|---|
| 52 | });
|
|---|
| 53 | writer.println('LF:' + summary.lines.total);
|
|---|
| 54 | writer.println('LH:' + summary.lines.covered);
|
|---|
| 55 |
|
|---|
| 56 | Object.entries(branches).forEach(([key, branchArray]) => {
|
|---|
| 57 | const meta = branchMap[key];
|
|---|
| 58 | if (meta) {
|
|---|
| 59 | const { line } = meta.loc.start;
|
|---|
| 60 | branchArray.forEach((b, i) => {
|
|---|
| 61 | writer.println('BRDA:' + [line, key, i, b].join(','));
|
|---|
| 62 | });
|
|---|
| 63 | } else {
|
|---|
| 64 | console.warn('Missing coverage entries in', fileName, key);
|
|---|
| 65 | }
|
|---|
| 66 | });
|
|---|
| 67 | writer.println('BRF:' + summary.branches.total);
|
|---|
| 68 | writer.println('BRH:' + summary.branches.covered);
|
|---|
| 69 | writer.println('end_of_record');
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | onEnd() {
|
|---|
| 73 | this.contentWriter.close();
|
|---|
| 74 | }
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | module.exports = LcovOnlyReport;
|
|---|