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
process: make exitCode
configurable again
#49579
base: main
Are you sure you want to change the base?
Conversation
This change was done in nodejs#44711, and it's not clear it was intentional. It caused nodejs#45683, and also makes it impossible to mock out the exitCode in tests. Filing this PR per nodejs#44711 (comment) Fixes nodejs#45683.
Review requested:
|
I like this change, solves my problem. (I worked around it by just letting the code in my tests update the "real" process.exitCode and then verifying it's been set, and setting it back to 0. But that's less good, because it means I can't also verify that it was set the number of times I expect, in the places I expect, etc.) Another idea to consider, which would preserve the air-tight protection against non-number exitCode:
|
Is it worthwhile to add a test for this? |
Happy to if you can suggest where to put it :-) |
Maybe see if it's possible/reasonable to include it in If that doesn't seem like the right place, perhaps create a separate test file as |
What's interesting is that that test isn't failing now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 (agree with @Trott this should have a test)
The process.exitCode = 1;
delete process.exitCode;
process.exitCode = 0;
// With this patch, node will exit with 1, not 0. Previously, the JavaScript side hold the node/lib/internal/bootstrap/node.js Lines 123 to 124 in c55625f
Since v20, JavaScript side and the native side share the @isaacs I'm not entirely sure if I grasp your issue correctly, but it seems like you want to monitor changes in the exit code during testing. I'm not certain if this is a good idea, but would it resolve your issue if we would trigger an event along with a modified exit code whenever it's changed? |
If plugins export an `importLoader`, and Module.register exists, then use that instead of their `loader` export. process.exitCode became {configurable:false} in nodejs/node#44711 Can bring back exitCode interception when/if it becomes configurable again, re nodejs/node#49579 For now, just set it, and then verify it's the expected value, and put it back to 0 if so.
If plugins export an `importLoader`, and Module.register exists, then use that instead of their `loader` export. process.exitCode became {configurable:false} in nodejs/node#44711 Can bring back exitCode interception when/if it becomes configurable again, re nodejs/node#49579 For now, just set it, and then verify it's the expected value, and put it back to 0 if so.
Yes, it's for testing. It's somewhat less convenient to not be able to just do
Personally, I think that's fine. Put a note in the docs that |
I'm happy to add a test, but the existing |
It seems that process.exitCode = 0;
throws(() => {
delete process.exitCode; // configurable: true
}, /Cannot delete property 'exitCode' of #<process>/); In the test, we last set exitCode to 0 and then do node/lib/internal/process/execution.js Lines 156 to 167 in 48fcb20
In 165 line, the handler set exitCode to |
Is that a deeper bug that I should try to fix? |
Yes, it's needed to handle. |
This change was done in #44711, and it was unintentional. It caused #45683, and also makes it impossible to mock out the exitCode in tests. It affects all of node 19, and all of node 20 thus far (so it should not be backported to node 18 or earlier)
Filing this PR per #44711 (comment)
Refs: #44711
Fixes: #45683
cc @nodejs/process @nlf @daeyeon