ObjectUtils Class
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.
Item Index
Methods
- addDerivedInfo static
- addDerivedInfoForFile static
- blankSummary static
- mergeFileCoverage static
- mergeSummaryObjects static
- removeDerivedInfo static
- summarizeCoverage static
- summarizeFileCoverage static
- toYUICoverage static
Methods
addDerivedInfo
-
coverage
adds line coverage information to all file coverage objects.
Parameters:
-
coverage
Objectthe coverage object
addDerivedInfoForFile
-
fileCoverage
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
Objectthe 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:
a blank metrics object
mergeFileCoverage
-
first
-
second
merges two instances of file coverage objects for the same file such that the execution counts are correct.
Parameters:
-
first
Objectthe first file coverage object for a given file
-
second
Objectthe second file coverage object for the same file
Returns:
an object that is a result of merging the two. Note that the input objects are not changed in any way.
mergeSummaryObjects
-
summary...
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...
Objectmultiple summary metrics objects
Returns:
the merged summary metrics
removeDerivedInfo
-
coverage
removes line coverage information from all file coverage objects
Parameters:
-
coverage
Objectthe coverage object
summarizeCoverage
-
coverage
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
Objectthe coverage object
Returns:
summary coverage metrics across all files in the coverage object
summarizeFileCoverage
-
fileCoverage
returns the summary metrics given the coverage object for a single file. See blankSummary()
to understand the format of the returned object.
Parameters:
-
fileCoverage
Objectthe coverage object for a single file.
Returns:
the summary metrics for the file
toYUICoverage
-
coverage
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
ObjectThe
istanbul
coverage object
Returns:
a coverage object in yuitest_coverage
format.