diff --git a/lib/platform-shims/cjs.ts b/lib/platform-shims/cjs.ts index b4220be28..402dfaf9f 100644 --- a/lib/platform-shims/cjs.ts +++ b/lib/platform-shims/cjs.ts @@ -27,8 +27,8 @@ export default { argv: () => process.argv, cwd: process.cwd, execPath: () => process.execPath, - exit: () => { - process.exit() + exit: (code: number) => { + process.exit(code) }, nextTick: process.nextTick, stdColumns: typeof process.stdout.columns !== 'undefined' ? process.stdout.columns : null diff --git a/test/command.cjs b/test/command.cjs index 59eb1dc7e..fb625cbba 100644 --- a/test/command.cjs +++ b/test/command.cjs @@ -619,6 +619,7 @@ describe('Command', () => { .commandDir('fixtures/cmddir') .parse()) r.exit.should.equal(true) + r.exitCode.should.equal(0) r.errors.length.should.equal(0) r.should.have.property('logs') r.logs.join('\n').split(/\n+/).should.deep.equal([ @@ -1513,6 +1514,7 @@ describe('Command', () => { .parse() }) called.should.equal(false) + r.exitCode.should.equal(1) r.errors.should.match(/Missing required argument/) }) diff --git a/test/helpers/utils.cjs b/test/helpers/utils.cjs index 03166511c..7546d0d7c 100644 --- a/test/helpers/utils.cjs +++ b/test/helpers/utils.cjs @@ -6,6 +6,7 @@ const { format } = require('util') // assert against it. exports.checkOutput = function checkOutput(f, argv, cb) { let exit = false + let exitCode = 0 const _exit = process.exit const _emit = process.emit const _env = process.env @@ -14,7 +15,10 @@ exports.checkOutput = function checkOutput(f, argv, cb) { const _log = console.log const _warn = console.warn - process.exit = (() => { exit = true }) + process.exit = ((code) => { + exit = true + exitCode = code + }) process.env = Hash.merge(process.env, { _: 'node' }) process.argv = argv || ['./usage'] @@ -72,6 +76,7 @@ exports.checkOutput = function checkOutput(f, argv, cb) { logs, warnings, exit, + exitCode, result } }