fix: replace async-exit-hook with exit-hook to preserve process.exitCode#31
Open
AmineMaila wants to merge 1 commit into
Open
fix: replace async-exit-hook with exit-hook to preserve process.exitCode#31AmineMaila wants to merge 1 commit into
AmineMaila wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Replaces
async-exit-hookwithexit-hookto fix a bug whereprocess.exitCodewas always overridden to0on process exit.async-exit-hookunconditionally callsprocess.exit(0)after its cleanup hooks run, ignoring anyprocess.exitCodeset by the application. Theexit-hookpackage (by the same author, sindresorhus) hooks into process exit events without forcing the exit code, preserving whateverprocess.exitCodewas set.I encountered this while using vitest and embedded-postgres together for testing — when a test failed, vitest sets
process.exitCode = 1, butasync-exit-hookwould force it back to0, causing CI pipelines to incorrectly report the test run as successful.Changes
packages/embedded-postgres/package.json: Replacedasync-exit-hookdependency withexit-hookpackages/embedded-postgres/src/index.ts: Updated import fromAsyncExitHooktoasyncExitHook, removed thedonecallback parameter fromgracefulShutdown, added a 5-second wait timeoutpackages/embedded-postgres/tests/index.test.ts: Added test verifying thatprocess.exitCodeis preserved when usingEmbeddedPostgrespackages/embedded-postgres/tests/helpers/exit-code-test.mjs: Helper script for the exit code testTesting
EmbeddedPostgreswithprocess.exitCode = 42exits with code 42 (not 0)