Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: code was not passed to process.exit #1742

Merged
merged 2 commits into from Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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