API Docs for: 0.3.0
Show:

ObjectUtils Class

Defined in: lib/object-utils.js:6
Module: main

utility methods to process coverage objects. A coverage object has the following format.

 {
     "/path/to/file1.js": { file1 coverage },
     "/path/to/file2.js": { file2 coverage }
 }

The internals of the file coverage object are intentionally not documented since it is not a public interface.

Note: When a method of this module has the word File in it, it will accept one of the sub-objects of the main coverage object as an argument. Other methods accept the higher level coverage object with multiple keys.

Works on node as well as the browser.

Usage on nodejs

 var objectUtils = require('istanbul').utils;

Usage in a browser

Load this file using a script tag or other means. This will set window.coverageUtils to this module's exports.

Methods

addDerivedInfo

(
  • coverage
)
static

adds line coverage information to all file coverage objects.

Parameters:

  • coverage Object

    the coverage object

addDerivedInfoForFile

(
  • fileCoverage
)
static

adds line coverage information to a file coverage object, reverse-engineering it from statement coverage. The object passed in is updated in place.

Note that if line coverage information is already present in the object, it is not recomputed.

Parameters:

  • fileCoverage Object

    the coverage object for a single file

blankSummary

() Object static

returns a blank summary metrics object. A metrics object has the following format.

 {
     lines: lineMetrics,
     statements: statementMetrics,
     functions: functionMetrics,
     branches: branchMetrics
 }

Each individual metric object looks as follows:

 {
     total: n,
     covered: m,
     pct: percent
 }

Returns:

Object:

a blank metrics object

mergeFileCoverage

(
  • first
  • second
)
Object static

merges two instances of file coverage objects for the same file such that the execution counts are correct.

Parameters:

  • first Object

    the first file coverage object for a given file

  • second Object

    the second file coverage object for the same file

Returns:

Object:

an object that is a result of merging the two. Note that the input objects are not changed in any way.

mergeSummaryObjects

(
  • summary...
)
Object static

merges multiple summary metrics objects by summing up the totals and covered fields and recomputing the percentages. This function is generic and can accept any number of arguments.

Parameters:

  • summary... Object

    multiple summary metrics objects

Returns:

Object:

the merged summary metrics

removeDerivedInfo

(
  • coverage
)
static

removes line coverage information from all file coverage objects

Parameters:

  • coverage Object

    the coverage object

summarizeCoverage

(
  • coverage
)
Object static

returns the coverage summary for a single coverage object. This is wrapper over summarizeFileCoverage and mergeSummaryObjects for the common case of a single coverage object

Parameters:

  • coverage Object

    the coverage object

Returns:

Object:

summary coverage metrics across all files in the coverage object

summarizeFileCoverage

(
  • fileCoverage
)
Object static

returns the summary metrics given the coverage object for a single file. See blankSummary() to understand the format of the returned object.

Parameters:

  • fileCoverage Object

    the coverage object for a single file.

Returns:

Object:

the summary metrics for the file

toYUICoverage

(
  • coverage
)
Object static

makes the coverage object generated by this library yuitest_coverage compatible. Note that this transformation is lossy since the returned object will not have statement and branch coverage.

Parameters:

  • coverage Object

    The istanbul coverage object

Returns:

Object:

a coverage object in yuitest_coverage format.