1.0.0-alpha.2
istanbul-lib-coverage exports an API that allows you to create and manipulate file coverage, coverage maps (a set of file coverage objects) and summary coverage objects. File coverage for the same file can be merged as can entire coverage maps.
.classes
classes exported for reuse
classes exported for reuse
.FileCoverage
the file coverage constructor
the file coverage constructor
.createCoverageMap(obj)
creates a CoverageMap object
creates a CoverageMap object
Object
obj
:
optional - an argument with the same semantics as the one passed to the CoverageMap constructor.
CoverageMap
.createCoverageSummary(obj)
creates a coverage summary object
creates a coverage summary object
Object
obj
:
an argument with the same semantics
as the one passed to the CoverageSummary
constructor
CoverageSummary
.createFileCoverage(obj)
creates a FileCoverage object
creates a FileCoverage object
Object
obj
:
optional - an argument with the same semantics as the one passed to the FileCoverage constructor.
FileCoverage
CoverageMap is a map of FileCoverage
objects keyed by file paths.
[Object
]
obj
(default undefined
)
:
obj A coverage map from which to initialize this map's contents. This can be the raw global coverage object.
#addFileCoverage(fc)
adds a file coverage object to this map. If the path for the object, already exists in the map, it is merged with the existing coverage otherwise a new key is added to the map.
adds a file coverage object to this map. If the path for the object, already exists in the map, it is merged with the existing coverage otherwise a new key is added to the map.
FileCoverage
fc
:
the file coverage to add
#fileCoverageFor(file)
returns the file coverage for the specified file.
returns the file coverage for the specified file.
String
file
:
FileCoverage
#files
returns an array for file paths for which this map has coverage
returns an array for file paths for which this map has coverage
#getCoverageSummary
returns the coverage summary for all the file coverage objects in this map.
returns the coverage summary for all the file coverage objects in this map.
CoverageSummary
#merge(obj)
merges a second coverage map into this one
merges a second coverage map into this one
CoverageMap
obj
:
a CoverageMap or its raw data. Coverage is merged correctly for the same files and additional file coverage keys are created as needed.
#toJSON
returns a JSON-serializable POJO for this coverage map
returns a JSON-serializable POJO for this coverage map
Object
CoverageSummary provides a summary of code coverage . It exposes 4 properties,
lines
, statements
, branches
, and functions
. Each of these properties
is an object that has 4 keys total
, covered
, skipped
and pct
.
pct
is a percentage number (0-100).
[Object
or CoverageSummary
]
obj
(default undefined
)
:
an optional data object or another coverage summary to initialize this object with.
#merge(obj)
merges a second summary coverage object into this one
merges a second summary coverage object into this one
CoverageSummary
obj
:
another coverage summary object
#toJSON
returns a POJO that is JSON serializable. May be used to get the raw summary object.
returns a POJO that is JSON serializable. May be used to get the raw summary object.
provides a read-only view of coverage for a single file. The deep structure of this object is documented elsewhere. It has the following properties:
path
- the file path for which coverage is being trackedstatementMap
- map of statement locations keyed by statement indexfunctionMap
- map of function metadata keyed by function indexbranchMap
- map of branch metadata keyed by branch indexs
- hit counts for statementsf
- hit count for functionsb
- hit count for branchesObject
or FileCoverage
or String
pathOrObj
:
is a string that initializes and empty coverage object with the specified file path or a data object that has all the required properties for a file coverage object.
#getBranchCoverageByLine
returns a map of branch coverage by source line number.
returns a map of branch coverage by source line number.
Object
:
an object keyed by line number. Each object
has a covered
, total
and coverage
(percentage) property.
#getLineCoverage
returns computed line coverage from statement coverage. This is a map of hits keyed by line number in the source.
returns computed line coverage from statement coverage. This is a map of hits keyed by line number in the source.
#getUncoveredLines
returns an array of uncovered line numbers.
returns an array of uncovered line numbers.
Array
:
an array of line numbers for which no hits have been collected.
#merge(other)
merges a second coverage object into this one, updating hit counts
merges a second coverage object into this one, updating hit counts
FileCoverage
other
:
the coverage object to be merged into this one. Note that the other object should have the same structure as this one (same file).
#resetHits
resets hit counts for all statements, functions and branches in this coverage object resulting in zero coverage.
resets hit counts for all statements, functions and branches in this coverage object resulting in zero coverage.
#toJSON
return a JSON-serializable POJO for this file coverage object
return a JSON-serializable POJO for this file coverage object
#toSummary
returns a CoverageSummary for this file coverage object
returns a CoverageSummary for this file coverage object
CoverageSummary