@@ -441,21 +441,36 @@ NYC.prototype.showProcessTree = function () {
441441 console . log ( processTree . render ( this ) )
442442}
443443
444- NYC . prototype . checkCoverage = function ( thresholds ) {
444+ NYC . prototype . checkCoverage = function ( thresholds , perFile ) {
445445 var map = this . _getCoverageMapFromAllCoverageFiles ( )
446- var summary = map . getCoverageSummary ( )
446+ var nyc = this
447447
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 ) {
449463 Object . keys ( thresholds ) . forEach ( function ( key ) {
450464 var coverage = summary [ key ] . pct
451465 if ( coverage < thresholds [ key ] ) {
452466 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+ }
454472 }
455473 } )
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 )
459474}
460475
461476NYC . prototype . _loadProcessInfos = function ( ) {
0 commit comments