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

Error: Expected to exit with code 1 but it ran without exiting #465

Closed
JarnoRFB opened this issue Jan 13, 2024 · 4 comments
Closed

Error: Expected to exit with code 1 but it ran without exiting #465

JarnoRFB opened this issue Jan 13, 2024 · 4 comments

Comments

@JarnoRFB
Copy link

I am currently trying to test that a command exits with code 1. In the command, the code simply calls this.exit(1) and the test I am trying to assert with .exit(1). However, I am getting the error Error: Expected to exit with code 1 but it ran without exiting. See PR for context.

I have the suspicion that the exit test would always fail, as its run method always throws an error. How can I handle this situation?

Thanks in advance!

@mdonnalley
Copy link
Contributor

@JarnoRFB Calling this.exit throws an error, which the exit hook's catch method is supposed to pick up. If the run method is executed instead of the catch - that means that you're command didn't throw an error, which is why it's telling you that it ran without exiting.

If you modify the the catch method on the base command class is to throw an error here then your test will begin passing.

@JarnoRFB
Copy link
Author

@mdonnalley That makes a lot of sense. Thank you for the clarification!
As it is implemented right now, the base class seems to catch any error and just set the exit code to 1 in this case. Is there any way to assert the exit code in the test without requiring the command to throw an error?

@mdonnalley
Copy link
Contributor

You can just check that process.exitCode has been set to the expected code

@JarnoRFB
Copy link
Author

Thanks, that seems to work just fine 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants