diff --git a/bin/nyc.js b/bin/nyc.js index cd225844d..7c188e40a 100755 --- a/bin/nyc.js +++ b/bin/nyc.js @@ -85,5 +85,6 @@ if ([ }) } else { // I don't have a clue what you're doing. + process.exitCode = 1 yargs.showHelp() } diff --git a/test/nyc-integration.js b/test/nyc-integration.js index 91bd358ca..f7be9564a 100644 --- a/test/nyc-integration.js +++ b/test/nyc-integration.js @@ -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']