Skip to content

Commit

Permalink
fix: add shim for check-coverage on node 0.10 (#386)
Browse files Browse the repository at this point in the history
* fix: add shim for check-coverage on node 0.10

* fix: better, stronger, faster regex
  • Loading branch information
bcoe committed Sep 13, 2016
1 parent ec2920f commit 9ebaea8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,9 @@ NYC.prototype.checkCoverage = function (thresholds) {
console.error('ERROR: Coverage for ' + key + ' (' + coverage + '%) does not meet global threshold (' + thresholds[key] + '%)')
}
})

// process.exitCode was not implemented until v0.11.8.
if (/^v0\.(1[0-1]\.|[0-9]\.)/.test(process.version) && process.exitCode !== 0) process.exit(process.exitCode)
}

NYC.prototype._loadProcessInfoTree = function () {
Expand Down
22 changes: 22 additions & 0 deletions test/src/nyc-bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,28 @@ describe('the nyc cli', function () {
})
})

// https://github.com/istanbuljs/nyc/issues/384
it('fails when check-coverage command is used rather than flag', function (done) {
var args = [bin, 'check-coverage', '--lines', '51', process.execPath, './half-covered.js']
var message = 'ERROR: Coverage for lines (50%) does not meet global threshold (51%)'

var proc = spawn(process.execPath, args, {
cwd: fixturesCLI,
env: env
})

var stderr = ''
proc.stderr.on('data', function (chunk) {
stderr += chunk
})

proc.on('close', function (code) {
code.should.not.equal(0)
stderr.trim().should.equal(message)
done()
})
})

it('succeeds when the expected coverage is above a threshold', function (done) {
var args = [bin, '--check-coverage', '--lines', '49', process.execPath, './half-covered.js']

Expand Down

0 comments on commit 9ebaea8

Please sign in to comment.