Code coverage report for istanbul/lib/report/lcov.js

Statements: 100% (22 / 22)      Branches: 100% (6 / 6)      Functions: 100% (4 / 4)      Lines: 100% (22 / 22)      Ignored: none     

All files » istanbul/lib/report/ » lcov.js
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          89                                                 89 115 115 115     115 115 115     89 89   89   2     15 15 15 15 15 15     30 30 15         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'),
    util = require('util'),
    mkdirp = require('mkdirp'),
    Report = require('./index'),
    LcovOnlyReport = require('./lcovonly'),
    HtmlReport = require('./html');
 
/**
 * a `Report` implementation that produces an LCOV coverage file and an associated HTML report from coverage objects.
 * The name and behavior of this report is designed to ease migration for projects that currently use `yuitest_coverage`
 *
 * Usage
 * -----
 *
 *      var report = require('istanbul').Report.create('lcov');
 *
 *
 * @class LcovReport
 * @extends Report
 * @module report
 * @constructor
 * @param {Object} opts optional
 * @param {String} [opts.dir] the directory in which to the `lcov.info` file.
 *  HTML files are written in a subdirectory called `lcov-report`. Defaults to `process.cwd()`
 */
function LcovReport(opts) {
    Report.call(this);
    opts = opts || {};
    var baseDir = path.resolve(opts.dir || process.cwd()),
        htmlDir = path.resolve(baseDir, 'lcov-report');
 
    mkdirp.sync(baseDir);
    this.lcov = new LcovOnlyReport({ dir: baseDir, watermarks: opts.watermarks });
    this.html = new HtmlReport({ dir: htmlDir, watermarks: opts.watermarks, sourceStore: opts.sourceStore});
}
 
LcovReport.TYPE = 'lcov';
util.inherits(LcovReport, Report);
 
Report.mix(LcovReport, {
    synopsis: function () {
        return 'combined lcovonly and html report that generates an lcov.info file as well as HTML';
    },
    writeReport: function (collector, sync) {
        var handler = this.handleDone.bind(this);
        this.inProgress = 2;
        this.lcov.on('done', handler);
        this.html.on('done', handler);
        this.lcov.writeReport(collector, sync);
        this.html.writeReport(collector, sync);
    },
    handleDone: function () {
        this.inProgress -= 1;
        if (this.inProgress === 0) {
            this.emit('done');
        }
    }
});
 
module.exports = LcovReport;