Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add shim for check-coverage on node 0.10 #386

Merged
merged 2 commits into from
Sep 13, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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\.[0-10]/.test(process.version) && process.exitCode !== 0) process.exit(process.exitCode)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[0-10] matches exactly 0 and 1. :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops.

}

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