Skip to content

Commit 05fea60

Browse files
RyanVbcoe
authored andcommittedApr 7, 2018
feat: load coverage files individually instead of all at once, addressing memory issues (#806)
1 parent dd372f5 commit 05fea60

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed
 

‎index.js

+22-6
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ NYC.prototype._getCoverageMapFromAllCoverageFiles = function () {
425425
var _this = this
426426
var map = libCoverage.createCoverageMap({})
427427

428-
this.loadReports().forEach(function (report) {
428+
this.eachReport(function (report) {
429429
map.merge(report)
430430
})
431431
// depending on whether source-code is pre-instrumented
@@ -514,26 +514,42 @@ NYC.prototype._loadProcessInfos = function () {
514514
})
515515
}
516516

517-
NYC.prototype.loadReports = function (filenames) {
517+
NYC.prototype.eachReport = function (filenames, iterator) {
518+
if (typeof filenames === 'function') {
519+
iterator = filenames
520+
filenames = undefined
521+
}
522+
518523
var _this = this
519524
var files = filenames || fs.readdirSync(this.tempDirectory())
520525

521-
return files.map(function (f) {
526+
files.forEach(function (f) {
522527
var report
523528
try {
524529
report = JSON.parse(fs.readFileSync(
525530
path.resolve(_this.tempDirectory(), f),
526531
'utf-8'
527532
))
533+
534+
_this.sourceMaps.reloadCachedSourceMaps(report)
528535
} catch (e) { // handle corrupt JSON output.
529-
return {}
536+
report = {}
530537
}
531538

532-
_this.sourceMaps.reloadCachedSourceMaps(report)
533-
return report
539+
iterator(report)
534540
})
535541
}
536542

543+
NYC.prototype.loadReports = function (filenames) {
544+
var reports = []
545+
546+
this.eachReport(filenames, function (report) {
547+
reports.push(report)
548+
})
549+
550+
return reports
551+
}
552+
537553
NYC.prototype.tempDirectory = function () {
538554
return path.resolve(this.cwd, this._tempDirectory)
539555
}

‎lib/process.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ ProcessInfo.prototype.render = function (nyc) {
8181
this.getCoverageMap(function (filenames, maps) {
8282
var map = libCoverage.createCoverageMap({})
8383

84-
nyc.loadReports(filenames).forEach(function (report) {
84+
nyc.eachReport(filenames, function (report) {
8585
map.merge(report)
8686
})
8787

0 commit comments

Comments
 (0)
Please sign in to comment.