@@ -441,21 +441,36 @@ NYC.prototype.showProcessTree = function () {
441
441
console . log ( processTree . render ( this ) )
442
442
}
443
443
444
- NYC . prototype . checkCoverage = function ( thresholds ) {
444
+ NYC . prototype . checkCoverage = function ( thresholds , perFile ) {
445
445
var map = this . _getCoverageMapFromAllCoverageFiles ( )
446
- var summary = map . getCoverageSummary ( )
446
+ var nyc = this
447
447
448
- // ERROR: Coverage for lines (90.12%) does not meet global threshold (120%)
448
+ if ( perFile ) {
449
+ map . files ( ) . forEach ( function ( file ) {
450
+ // ERROR: Coverage for lines (90.12%) does not meet threshold (120%) for index.js
451
+ nyc . _checkCoverage ( map . fileCoverageFor ( file ) . toSummary ( ) , thresholds , file )
452
+ } )
453
+ } else {
454
+ // ERROR: Coverage for lines (90.12%) does not meet global threshold (120%)
455
+ nyc . _checkCoverage ( map . getCoverageSummary ( ) , thresholds )
456
+ }
457
+
458
+ // process.exitCode was not implemented until v0.11.8.
459
+ if ( / ^ v 0 \. ( 1 [ 0 - 1 ] \. | [ 0 - 9 ] \. ) / . test ( process . version ) && process . exitCode !== 0 ) process . exit ( process . exitCode )
460
+ }
461
+
462
+ NYC . prototype . _checkCoverage = function ( summary , thresholds , file ) {
449
463
Object . keys ( thresholds ) . forEach ( function ( key ) {
450
464
var coverage = summary [ key ] . pct
451
465
if ( coverage < thresholds [ key ] ) {
452
466
process . exitCode = 1
453
- console . error ( 'ERROR: Coverage for ' + key + ' (' + coverage + '%) does not meet global threshold (' + thresholds [ key ] + '%)' )
467
+ if ( file ) {
468
+ console . error ( 'ERROR: Coverage for ' + key + ' (' + coverage + '%) does not meet threshold (' + thresholds [ key ] + '%) for ' + file )
469
+ } else {
470
+ console . error ( 'ERROR: Coverage for ' + key + ' (' + coverage + '%) does not meet global threshold (' + thresholds [ key ] + '%)' )
471
+ }
454
472
}
455
473
} )
456
-
457
- // process.exitCode was not implemented until v0.11.8.
458
- if ( / ^ v 0 \. ( 1 [ 0 - 1 ] \. | [ 0 - 9 ] \. ) / . test ( process . version ) && process . exitCode !== 0 ) process . exit ( process . exitCode )
459
474
}
460
475
461
476
NYC . prototype . _loadProcessInfos = function ( ) {
0 commit comments