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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | 89 89 220 220 220 220 89 89 89 2 309 1079 1079 1079 1079 1104 1104 1079 1079 1079 1104 1104 1079 1283 1283 1079 1079 1079 56 56 112 112 1079 1079 1079 23 23 23 23 1079 23 89 | /* Copyright (c) 2012, Yahoo! Inc. All rights reserved. Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms. */ var path = require('path'), Writer = require('../util/file-writer'), util = require('util'), Report = require('./index'), utils = require('../object-utils'); /** * a `Report` implementation that produces an LCOV coverage file from coverage objects. * * Usage * ----- * * var report = require('istanbul').Report.create('lcovonly'); * * * @class LcovOnlyReport * @extends Report * @module report * @constructor * @param {Object} opts optional * @param {String} [opts.dir] the directory in which to the `lcov.info` file. Defaults to `process.cwd()` */ function LcovOnlyReport(opts) { this.opts = opts || {}; this.opts.dir = this.opts.dir || process.cwd(); this.opts.file = this.opts.file || this.getDefaultConfig().file; this.opts.writer = this.opts.writer || null; } LcovOnlyReport.TYPE = 'lcovonly'; util.inherits(LcovOnlyReport, Report); Report.mix(LcovOnlyReport, { synopsis: function () { return 'lcov coverage report that can be consumed by the lcov tool'; }, getDefaultConfig: function () { return { file: 'lcov.info' }; }, writeFileCoverage: function (writer, fc) { var functions = fc.f, functionMap = fc.fnMap, lines = fc.l, branches = fc.b, branchMap = fc.branchMap, summary = utils.summarizeFileCoverage(fc); writer.println('TN:'); //no test name writer.println('SF:' + fc.path); Object.keys(functions).forEach(function (key) { var meta = functionMap[key]; writer.println('FN:' + [ meta.line, meta.name ].join(',')); }); writer.println('FNF:' + summary.functions.total); writer.println('FNH:' + summary.functions.covered); Object.keys(functions).forEach(function (key) { var stats = functions[key], meta = functionMap[key]; writer.println('FNDA:' + [ stats, meta.name ].join(',')); }); Object.keys(lines).forEach(function (key) { var stat = lines[key]; writer.println('DA:' + [ key, stat ].join(',')); }); writer.println('LF:' + summary.lines.total); writer.println('LH:' + summary.lines.covered); Object.keys(branches).forEach(function (key) { var branchArray = branches[key], meta = branchMap[key], line = meta.line, i = 0; branchArray.forEach(function (b) { writer.println('BRDA:' + [line, key, i, b].join(',')); i += 1; }); }); writer.println('BRF:' + summary.branches.total); writer.println('BRH:' + summary.branches.covered); writer.println('end_of_record'); }, writeReport: function (collector, sync) { var outputFile = path.resolve(this.opts.dir, this.opts.file), writer = this.opts.writer || new Writer(sync), that = this; writer.on('done', function () { that.emit('done'); }); writer.writeFile(outputFile, function (contentWriter) { collector.files().forEach(function (key) { that.writeFileCoverage(contentWriter, collector.fileCoverageFor(key)); }); }); writer.done(); } }); module.exports = LcovOnlyReport; |