lib/collector.js
/**
 * a mechanism to merge multiple coverage objects into one. Handles the use case
 * of overlapping coverage information for the same files in multiple coverage
 * objects and does not double-count in this situation. For example, if
 * you pass the same coverage object multiple times, the final merged object will be
 * no different that any of the objects passed in (except for execution counts).
 *
 * The `Collector` is built for scale to handle thousands of coverage objects.
 * By default, all processing is done in memory since the common use-case is of
 * one or a few coverage objects. You can work around memory
 * issues by passing in a `Store` implementation that stores temporary computations
 * on disk (the `tmp` store, for example).
 *
 * The `getFinalCoverage` method returns an object with merged coverage information
 * and is provided as a convenience for implementers working with coverage information
 * that can fit into memory. Reporters, in the interest of generality, should *not* use this method for
 * creating reports.
 *
 * Usage
 * -----
 *
 *      var collector = new require('istanbul').Collector();
 *
 *      files.forEach(function (f) {
 *          //each coverage object can have overlapping information about multiple files
 *          collector.add(JSON.parse(fs.readFileSync(f, 'utf8')));
 *      });
 *
 *      collector.files().forEach(function(file) {
 *          var fileCoverage = collector.fileCoverageFor(file);
 *          console.log('Coverage for ' + file + ' is:' + JSON.stringify(fileCoverage));
 *      });
 *
 *      // convenience method: do not use this when dealing with a large number of files
 *      var finalCoverage = collector.getFinalCoverage();
 *
 * @class Collector
 * @module main
 * @constructor
 * @param {Object} options Optional. Configuration options.
 * @param {Store} options.store - an implementation of `Store` to use for temporary
 *      calculations.
 * @param {Boolean} options.skipSourceMaps - true to indicate that source map processing
 *      should be skipped. Used internally to provide a reporting collector that
 *      itself already has source maps processed.
 */
a mechanism to merge multiple coverage objects into one. Handles the use case
of overlapping coverage information for the same files in multiple coverage
objects and does not double-count in this situation. For example, if
you pass the same coverage object multiple times, the final merged object will be
no different that any of the objects passed in (except for execution counts).

The `Collector` is built for scale to handle thousands of coverage objects.
By default, all processing is done in memory since the common use-case is of
one or a few coverage objects. You can work around memory
issues by passing in a `Store` implementation that stores temporary computations
on disk (the `tmp` store, for example).

The `getFinalCoverage` method returns an object with merged coverage information
and is provided as a convenience for implementers working with coverage information
that can fit into memory. Reporters, in the interest of generality, should *not* use this method for
creating reports.

Usage

var collector = new require('istanbul').Collector().

files.forEach(function (f) {
each coverage object can have overlapping information about multiple files
collector.add(JSON.parse(fs.readFileSync(f, 'utf8')));
}).



convenience method: do not use this when dealing with a large number of files
var finalCoverage = collector.getFinalCoverage().

@class Collector
@module main
@constructor
@param {Object} options Optional. Configuration options.
@param {Store} options.store - an implementation of `Store` to use for temporary
calculations.
@param {Boolean} options.skipSourceMaps - true to indicate that source map processing
should be skipped. Used internally to provide a reporting collector that
itself already has source maps processed.
a mechanism to merge multiple coverage objects into one . Handles the use case of overlapping coverage information for the same files in multiple coverage objects and does not double - count in this situation . For example if you pass the same coverage object multiple times the final merged object will be no different that any of the objects passed in ( except for execution counts ) . The ` Collector ` is built for scale to handle thousands of coverage objects . By default all processing is done in memory since the common use - case is of one or a few coverage objects . You can work around memory issues by passing in a ` Store ` implementation that stores temporary computations on disk ( the ` tmp ` store for example ) . The ` getFinalCoverage ` method returns an object with merged coverage information and is provided as a convenience for implementers working with coverage information that can fit into memory . Reporters in the interest of generality should * not * use this method for creating reports . Usage var collector = new require ( ' istanbul ' ) . Collector () . files . forEach ( function ( f ) { each coverage object can have overlapping information about multiple files collector . add ( JSON . parse ( fs . readFileSync ( f ' utf8 ' ))) ; } ) . convenience method : do not use this when dealing with a large number of files var finalCoverage = collector . getFinalCoverage () . @class Collector @module main @constructor @param { Object } options Optional . Configuration options . @param { Store } options . store - an implementation of ` Store ` to use for temporary calculations . @param { Boolean } options . skipSourceMaps - true to indicate that source map processing should be skipped . Used internally to provide a reporting collector that itself already has source maps processed .
function Collector(options) {
    options = options || {};
    this.store = options.store || new MemoryStore();
    this.reportStore = null;
    this.skipSourceMaps = options.skipSourceMaps;
    this.cache = sourceMaps.createCache();
    this.doneCalled = false;
}
function Collector ( options ) { options = options || { } ; this . store = options . store || new MemoryStore ( ) ; this . reportStore = null ; this . skipSourceMaps = options . skipSourceMaps ; this . cache = sourceMaps . createCache ( ) ; this . doneCalled = false ; }
a mechanism to merge multiple coverage objects into one.
a mechanism to merge multiple coverage objects into one .