Skip to content

Commit

Permalink
fix: Exit with code 1 when nyc doesn't know what to do.
Browse files Browse the repository at this point in the history
When nyc is not told to do anything this is an error.  We already
printed the help message to stderr, now we exit with code 1 to indicate
that nyc exited without doing anything.

Add a test to cover this edge case and verify that both `nyc` and `nyc
--help` produce output as expected to stdout and stderr, exit with the
proper code.
  • Loading branch information
coreyfarrell committed Apr 17, 2019
1 parent ca37ffa commit 9029c20
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions bin/nyc.js
Expand Up @@ -85,5 +85,6 @@ if ([
})
} else {
// I don't have a clue what you're doing.
process.exitCode = 1
yargs.showHelp()
}
34 changes: 34 additions & 0 deletions test/nyc-integration.js
Expand Up @@ -1079,6 +1079,40 @@ describe('the nyc cli', function () {
})
})

it('help shows to stderr when main command doesn\'t know what to do', done => {
const msgs = {}
let waitingFor = 2
const doSpawn = (args, type, expectCode) => {
const proc = spawn(process.execPath, args, {
cwd: fixturesCLI,
env
})
msgs[type] = {
out: '',
err: ''
}
proc.stdout.on('data', chunk => {
msgs[type].out += chunk
})
proc.stderr.on('data', chunk => {
msgs[type].err += chunk
})
proc.on('close', code => {
code.should.equal(expectCode)
waitingFor--
if (waitingFor === 0) {
msgs.help.out.should.equal(msgs.unknown.err)
msgs.help.err.should.equal('')
msgs.unknown.out.should.equal('')
done()
}
})
}

doSpawn([bin, '--help'], 'help', 0)
doSpawn([bin], 'unknown', 1)
})

describe('args', function () {
it('does not interpret args intended for instrumented bin', function (done) {
var args = [bin, '--silent', process.execPath, 'args.js', '--help', '--version']
Expand Down

0 comments on commit 9029c20

Please sign in to comment.