Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: code was not passed to process.exit (#1742)
  • Loading branch information
bcoe committed Sep 9, 2020
1 parent 5e5e5d0 commit d1a9930
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/platform-shims/cjs.ts
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/command.cjs
Expand Up @@ -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([
Expand Down Expand Up @@ -1513,6 +1514,7 @@ describe('Command', () => {
.parse()
})
called.should.equal(false)
r.exitCode.should.equal(1)
r.errors.should.match(/Missing required argument/)
})

Expand Down
7 changes: 6 additions & 1 deletion test/helpers/utils.cjs
Expand Up @@ -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
Expand All @@ -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']

Expand Down Expand Up @@ -72,6 +76,7 @@ exports.checkOutput = function checkOutput(f, argv, cb) {
logs,
warnings,
exit,
exitCode,
result
}
}
Expand Down

0 comments on commit d1a9930

Please sign in to comment.