@@ -425,7 +425,7 @@ NYC.prototype._getCoverageMapFromAllCoverageFiles = function () {
425
425
var _this = this
426
426
var map = libCoverage . createCoverageMap ( { } )
427
427
428
- this . loadReports ( ) . forEach ( function ( report ) {
428
+ this . eachReport ( function ( report ) {
429
429
map . merge ( report )
430
430
} )
431
431
// depending on whether source-code is pre-instrumented
@@ -514,26 +514,42 @@ NYC.prototype._loadProcessInfos = function () {
514
514
} )
515
515
}
516
516
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
+
518
523
var _this = this
519
524
var files = filenames || fs . readdirSync ( this . tempDirectory ( ) )
520
525
521
- return files . map ( function ( f ) {
526
+ files . forEach ( function ( f ) {
522
527
var report
523
528
try {
524
529
report = JSON . parse ( fs . readFileSync (
525
530
path . resolve ( _this . tempDirectory ( ) , f ) ,
526
531
'utf-8'
527
532
) )
533
+
534
+ _this . sourceMaps . reloadCachedSourceMaps ( report )
528
535
} catch ( e ) { // handle corrupt JSON output.
529
- return { }
536
+ report = { }
530
537
}
531
538
532
- _this . sourceMaps . reloadCachedSourceMaps ( report )
533
- return report
539
+ iterator ( report )
534
540
} )
535
541
}
536
542
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
+
537
553
NYC . prototype . tempDirectory = function ( ) {
538
554
return path . resolve ( this . cwd , this . _tempDirectory )
539
555
}
0 commit comments