2 Copyright (c) 2012, Yahoo! Inc. All rights reserved.
3 Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
6 var util = require('util'),
7 EventEmitter = require('events').EventEmitter,
8 Factory = require('../util/factory'),
9 factory = new Factory('report', __dirname, false);
11 * An abstraction for producing coverage reports.
12 * This class is both the base class as well as a factory for `Report` implementations.
13 * All reports are event emitters and are expected to emit a `done` event when
14 * the report writing is complete.
16 * See also the `Reporter` class for easily producing multiple coverage reports
22 * var Report = require('istanbul').Report,
23 * report = Report.create('html'),
24 * collector = new require('istanbul').Collector;
26 * collector.add(coverageObject);
27 * report.on('done', function () { console.log('done'); });
28 * report.writeReport(collector);
35 * @param {Object} options Optional. The options supported by a specific store implementation.
37 function Report(/* options */) {
38 EventEmitter.call(this);
41 util.inherits(Report, EventEmitter);
43 //add register, create, mix, loadAll, getReportList as class methods
44 factory.bindClassMethods(Report);
47 * registers a new report implementation.
50 * @param {Function} constructor the constructor function for the report. This function must have a
51 * `TYPE` property of type String, that will be used in `Report.create()`
54 * returns a report implementation of the specified type.
57 * @param {String} type the type of report to create
58 * @param {Object} opts Optional. Options specific to the report implementation
59 * @return {Report} a new store of the specified type
62 * returns the list of available reports as an array of strings
63 * @method getReportList
65 * @return an array of supported report formats
70 * returns a one-line summary of the report
72 * @return {String} a description of what the report is about
74 synopsis: function () {
75 throw new Error('synopsis must be overridden');
78 * returns a config object that has override-able keys settable via config
79 * @method getDefaultConfig
80 * @return {Object|null} an object representing keys that can be overridden via
81 * the istanbul configuration where the values are the defaults used when
82 * not specified. A null return implies no config attributes
84 getDefaultConfig: function () {
88 * writes the report for a set of coverage objects added to a collector.
90 * @param {Collector} collector the collector for getting the set of files and coverage
91 * @param {Boolean} sync true if reports must be written synchronously, false if they can be written using asynchronous means (e.g. stream.write)
93 writeReport: function (/* collector, sync */) {
94 throw new Error('writeReport: must be overridden');
98 Object.keys(proto).forEach(function (k) {
99 Report.prototype[k] = proto[k];
102 module.exports = Report;