Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ NYC.prototype._getCoverageMapFromAllCoverageFiles = function () {
var _this = this
var map = libCoverage.createCoverageMap({})

this.loadReports().forEach(function (report) {
this.eachReport(function (report) {
map.merge(report)
})
// depending on whether source-code is pre-instrumented
Expand Down Expand Up @@ -514,26 +514,42 @@ NYC.prototype._loadProcessInfos = function () {
})
}

NYC.prototype.loadReports = function (filenames) {
NYC.prototype.eachReport = function (filenames, iterator) {
if (typeof filenames === 'function') {
iterator = filenames
filenames = undefined
}

var _this = this
var files = filenames || fs.readdirSync(this.tempDirectory())

return files.map(function (f) {
files.forEach(function (f) {
var report
try {
report = JSON.parse(fs.readFileSync(
path.resolve(_this.tempDirectory(), f),
'utf-8'
))

_this.sourceMaps.reloadCachedSourceMaps(report)
} catch (e) { // handle corrupt JSON output.
return {}
report = {}
}

_this.sourceMaps.reloadCachedSourceMaps(report)
return report
iterator(report)
})
}

NYC.prototype.loadReports = function (filenames) {
var reports = []

this.eachReport(filenames, function (report) {
reports.push(report)
})

return reports
}

NYC.prototype.tempDirectory = function () {
return path.resolve(this.cwd, this._tempDirectory)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ ProcessInfo.prototype.render = function (nyc) {
this.getCoverageMap(function (filenames, maps) {
var map = libCoverage.createCoverageMap({})

nyc.loadReports(filenames).forEach(function (report) {
nyc.eachReport(filenames, function (report) {
map.merge(report)
})

Expand Down