Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / istanbul / lib / report / lcovonly.js
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 var path = require('path'),
7     Writer = require('../util/file-writer'),
8     util = require('util'),
9     Report = require('./index'),
10     utils = require('../object-utils');
11 /**
12  * a `Report` implementation that produces an LCOV coverage file from coverage objects.
13  *
14  * Usage
15  * -----
16  *
17  *      var report = require('istanbul').Report.create('lcovonly');
18  *
19  *
20  * @class LcovOnlyReport
21  * @extends Report
22  * @module report
23  * @constructor
24  * @param {Object} opts optional
25  * @param {String} [opts.dir] the directory in which to the `lcov.info` file. Defaults to `process.cwd()`
26  */
27 function LcovOnlyReport(opts) {
28     this.opts = opts || {};
29     this.opts.dir = this.opts.dir || process.cwd();
30     this.opts.file = this.opts.file || this.getDefaultConfig().file;
31     this.opts.writer = this.opts.writer || null;
32 }
33 LcovOnlyReport.TYPE = 'lcovonly';
34 util.inherits(LcovOnlyReport, Report);
35
36 Report.mix(LcovOnlyReport, {
37     synopsis: function () {
38         return 'lcov coverage report that can be consumed by the lcov tool';
39     },
40     getDefaultConfig: function () {
41         return { file: 'lcov.info' };
42     },
43     writeFileCoverage: function (writer, fc) {
44         var functions = fc.f,
45             functionMap = fc.fnMap,
46             lines = fc.l,
47             branches = fc.b,
48             branchMap = fc.branchMap,
49             summary = utils.summarizeFileCoverage(fc);
50
51         writer.println('TN:'); //no test name
52         writer.println('SF:' + fc.path);
53
54         Object.keys(functions).forEach(function (key) {
55             var meta = functionMap[key];
56             writer.println('FN:' + [ meta.line, meta.name ].join(','));
57         });
58         writer.println('FNF:' + summary.functions.total);
59         writer.println('FNH:' + summary.functions.covered);
60
61         Object.keys(functions).forEach(function (key) {
62             var stats = functions[key],
63                 meta = functionMap[key];
64             writer.println('FNDA:' + [ stats, meta.name ].join(','));
65         });
66
67         Object.keys(lines).forEach(function (key) {
68             var stat = lines[key];
69             writer.println('DA:' + [ key, stat ].join(','));
70         });
71         writer.println('LF:' + summary.lines.total);
72         writer.println('LH:' + summary.lines.covered);
73
74         Object.keys(branches).forEach(function (key) {
75             var branchArray = branches[key],
76                 meta = branchMap[key],
77                 line = meta.line,
78                 i = 0;
79             branchArray.forEach(function (b) {
80                 writer.println('BRDA:' + [line, key, i, b].join(','));
81                 i += 1;
82             });
83         });
84         writer.println('BRF:' + summary.branches.total);
85         writer.println('BRH:' + summary.branches.covered);
86         writer.println('end_of_record');
87     },
88
89     writeReport: function (collector, sync) {
90         var outputFile = path.resolve(this.opts.dir, this.opts.file),
91             writer = this.opts.writer || new Writer(sync),
92             that = this;
93         writer.on('done', function () { that.emit('done'); });
94         writer.writeFile(outputFile, function (contentWriter) {
95             collector.files().forEach(function (key) {
96                 that.writeFileCoverage(contentWriter, collector.fileCoverageFor(key));
97             });
98         });
99         writer.done();
100     }
101 });
102
103 module.exports = LcovOnlyReport;