API Docs for: 0.3.0
Show:

Collector Class

Defined in: lib/collector.js:9
Module: main

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 implementors 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();

Constructor

Collector

(
  • options
)

Defined in lib/collector.js:9

Parameters:

  • options Object

    Optional. Configuration options.

    • store Store
      • an implementation of Store to use for temporary calculations.

Methods

add

(
  • coverage
  • testName
)

Defined in lib/collector.js:58

adds a coverage object to the collector.

Parameters:

  • coverage Object

    the coverage object.

  • testName String

    Optional. The name of the test used to produce the object. This is currently not used.

dispose

()

disposes this collector and reclaims temporary resources used in the computation. Calls dispose() on the underlying store.

fileCoverageFor

(
  • fileName
)
Object

Defined in lib/collector.js:85

return file coverage information for a single file

Parameters:

  • fileName String

    the path for the file for which coverage information is required. Must be one of the values returned in the files() method.

Returns:

Object:

the coverage information for the specified file.

files

() Array

Defined in lib/collector.js:77

returns a list of unique file paths for which coverage information has been added.

Returns:

Array:

an array of file paths for which coverage information is present.

getFinalCoverage

() Object

Defined in lib/collector.js:97

returns file coverage information for all files. This has the same format as any of the objects passed in to the add method. The number of keys in this object will be a superset of all keys found in the objects passed to add()

Returns:

Object:

the merged coverage information