From 9ebaea8e274b0120134ff1546c77a929eece9d0f Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Mon, 12 Sep 2016 22:02:53 -0700 Subject: [PATCH] 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 --- index.js | 3 +++ test/src/nyc-bin.js | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/index.js b/index.js index 993a9744f..1517a5528 100755 --- a/index.js +++ b/index.js @@ -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 () { diff --git a/test/src/nyc-bin.js b/test/src/nyc-bin.js index faa2ff4d1..e6fe04bed 100644 --- a/test/src/nyc-bin.js +++ b/test/src/nyc-bin.js @@ -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']