this.exit(0) no longer exits in v3
maxbeatty opened this issue · comments
Describe the bug
this.exit(0)
used to exit with a code of zero in v2. In v3, this behavior has changed in that a command no longer exits.
To Reproduce
Reproduction repository: https://github.com/maxbeatty/reproduce-oclif-test-exit-zero
Simple command that can exit in different ways:
https://github.com/maxbeatty/reproduce-oclif-test-exit-zero/blob/2dfa70a1ab80b057167c3f4a9eb1f58701b125cc/src/commands/hello/index.ts#L20-L40
Tests for exit logic:
https://github.com/maxbeatty/reproduce-oclif-test-exit-zero/blob/2dfa70a1ab80b057167c3f4a9eb1f58701b125cc/test/commands/hello/index.test.ts#L11-L32
CI failure:
https://github.com/maxbeatty/reproduce-oclif-test-exit-zero/actions/runs/6670925950/job/18131787718
Downgrading to v2 restores expected behavior:
- https://github.com/maxbeatty/reproduce-oclif-test-exit-zero/pull/2/files
- https://github.com/maxbeatty/reproduce-oclif-test-exit-zero/actions/runs/6670912544/job/18131748129
Expected behavior
this.exit(code)
should exit the command with the given code.
Environment (please complete the following information):
- OS & version: observed locally in macOS and in GitHub Actions on Ubuntu
- Shell/terminal & version: does not seem to be related
@mdonnalley thanks for restoring the exit behavior! I noticed in your PR that you're using .catch(/EEXIT: 0/)
in your tests. Is it possible to use .exit(0)
instead for more consistency between the command and test (i.e., the command calls this.exit
so my test would verify that with test.exit
)?
maxbeatty/reproduce-oclif-test-exit-zero#7 is upgrading to the newest version of @oclif/test but failing because I am using .exit(0)
@maxbeatty Yes, it is possible. Those test are, for some unknown reason, using fancy-test
directly instead of @oclif/test
, which is what exposes the .exit
option.
If I had rewritten it to use @ocilf/test
it would have looked like this:
import {test} from '@oclif/test'
test
.stdout()
.do(() => {
class Command extends Base {
async run() {
this.exit(0)
}
}
return Command.run([])
})
.exit(0)
.it('exits with 0')
apologies for the oversight on my end. this is all working as expected now. thank you!