Skip to content

Commit 9ebaea8

Browse files
authored
fix: add shim for check-coverage on node 0.10 (#386)
* fix: add shim for check-coverage on node 0.10 * fix: better, stronger, faster regex
1 parent ec2920f commit 9ebaea8

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

index.js

+3
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,9 @@ NYC.prototype.checkCoverage = function (thresholds) {
467467
console.error('ERROR: Coverage for ' + key + ' (' + coverage + '%) does not meet global threshold (' + thresholds[key] + '%)')
468468
}
469469
})
470+
471+
// process.exitCode was not implemented until v0.11.8.
472+
if (/^v0\.(1[0-1]\.|[0-9]\.)/.test(process.version) && process.exitCode !== 0) process.exit(process.exitCode)
470473
}
471474

472475
NYC.prototype._loadProcessInfoTree = function () {

test/src/nyc-bin.js

+22
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,28 @@ describe('the nyc cli', function () {
9090
})
9191
})
9292

93+
// https://github.com/istanbuljs/nyc/issues/384
94+
it('fails when check-coverage command is used rather than flag', function (done) {
95+
var args = [bin, 'check-coverage', '--lines', '51', process.execPath, './half-covered.js']
96+
var message = 'ERROR: Coverage for lines (50%) does not meet global threshold (51%)'
97+
98+
var proc = spawn(process.execPath, args, {
99+
cwd: fixturesCLI,
100+
env: env
101+
})
102+
103+
var stderr = ''
104+
proc.stderr.on('data', function (chunk) {
105+
stderr += chunk
106+
})
107+
108+
proc.on('close', function (code) {
109+
code.should.not.equal(0)
110+
stderr.trim().should.equal(message)
111+
done()
112+
})
113+
})
114+
93115
it('succeeds when the expected coverage is above a threshold', function (done) {
94116
var args = [bin, '--check-coverage', '--lines', '49', process.execPath, './half-covered.js']
95117

0 commit comments

Comments
 (0)