Skip to content

Commit

Permalink
cleanup: simplify istanbul-lib-coverage API usage (#369)
Browse files Browse the repository at this point in the history
- Deduplicate merging of all coverage files
- Use the `map.getCoverageSummary()` convenience method
- Use convenience getters of `CoverageSummary` objects
  • Loading branch information
addaleax authored and bcoe committed Aug 27, 2016
1 parent d9709f8 commit 6d32604
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,17 +391,23 @@ function coverageFinder () {
return coverage
}

NYC.prototype.report = function () {
var tree
NYC.prototype._getCoverageMapFromAllCoverageFiles = function () {
var map = libCoverage.createCoverageMap({})
var context = libReport.createContext({
dir: this._reportDir
})

this._loadReports().forEach(function (report) {
map.merge(report)
})

return map
}

NYC.prototype.report = function () {
var tree
var map = this._getCoverageMapFromAllCoverageFiles()
var context = libReport.createContext({
dir: this._reportDir
})

tree = libReport.summarizers.pkg(map)

this.reporter.forEach(function (_reporter) {
Expand All @@ -410,22 +416,12 @@ NYC.prototype.report = function () {
}

NYC.prototype.checkCoverage = function (thresholds) {
var map = libCoverage.createCoverageMap({})
var summary = libCoverage.createCoverageSummary()

this._loadReports().forEach(function (report) {
map.merge(report)
})

map.files().forEach(function (f) {
var fc = map.fileCoverageFor(f)
var s = fc.toSummary()
summary.merge(s)
})
var map = this._getCoverageMapFromAllCoverageFiles()
var summary = map.getCoverageSummary()

// ERROR: Coverage for lines (90.12%) does not meet global threshold (120%)
Object.keys(thresholds).forEach(function (key) {
var coverage = summary.data[key].pct
var coverage = summary[key].pct
if (coverage < thresholds[key]) {
process.exitCode = 1
console.error('ERROR: Coverage for ' + key + ' (' + coverage + '%) does not meet global threshold (' + thresholds[key] + '%)')
Expand Down

0 comments on commit 6d32604

Please sign in to comment.