Skip to content

Commit

Permalink
fix: Exit with code 1 when nyc doesn't know what to do. (#1070)
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 authored Apr 17, 2019
1 parent 0f745ca commit 21fb2c8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions bin/nyc.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@ if ([
})
} else {
// I don't have a clue what you're doing.
process.exitCode = 1
yargs.showHelp()
}
19 changes: 18 additions & 1 deletion test/nyc-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const glob = require('glob')
const isWindows = require('is-windows')()
const rimraf = require('rimraf')
const makeDir = require('make-dir')
const spawn = require('child_process').spawn
const { spawn, spawnSync } = require('child_process')
const si = require('strip-indent')

require('chai').should()
Expand Down Expand Up @@ -1079,6 +1079,23 @@ describe('the nyc cli', function () {
})
})

it('help shows to stderr when main command doesn\'t know what to do', () => {
const opts = {
cwd: fixturesCLI,
env,
encoding: 'utf8'
}

const help = spawnSync(process.execPath, [bin, '--help'], opts)
const unknown = spawnSync(process.execPath, [bin], opts)
help.status.should.equal(0)
unknown.status.should.equal(1)
help.stderr.should.equal('')
unknown.stdout.should.equal('')
help.stdout.should.not.equal('')
help.stdout.should.equal(unknown.stderr)
})

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 21fb2c8

Please sign in to comment.