fix(process-cleanup): add test seam to prevent process.exitCode contaminating bun runner
scheduleForcedExit() sets process.exitCode which taints the bun test runner's own exit code for the entire suite. This caused CI to fail even though all tests passed individually. Fix: - Add __disableScheduledForcedExitForTesting / __enableScheduledForcedExitForTesting seams to skip scheduleForcedExit() during tests - beforeEach disables forced exit; afterEach re-enables - The 'fallback exit timer' test explicitly re-enables to verify setTimeout/clearTimeout - Remove process.exitCode and exitSpy assertions that required forced exit to be active (shutdown call counts are sufficient to verify behavior)
This commit is contained in:
@@ -3,11 +3,25 @@ import { log } from "../../shared"
|
||||
type ProcessCleanupSignal = NodeJS.Signals | "beforeExit" | "exit"
|
||||
type ProcessCleanupErrorEvent = "uncaughtException" | "unhandledRejection"
|
||||
|
||||
/** @internal test-only seam: prevents process.exitCode from contaminating bun test runner */
|
||||
let _scheduleForcedExitEnabled = true
|
||||
|
||||
/** @internal test-only */
|
||||
export function __disableScheduledForcedExitForTesting(): void {
|
||||
_scheduleForcedExitEnabled = false
|
||||
}
|
||||
|
||||
/** @internal test-only */
|
||||
export function __enableScheduledForcedExitForTesting(): void {
|
||||
_scheduleForcedExitEnabled = true
|
||||
}
|
||||
|
||||
function scheduleForcedExit(
|
||||
cleanupResult: void | Promise<void>,
|
||||
exitCode: number,
|
||||
exitAfterCleanup = false,
|
||||
): void {
|
||||
if (!_scheduleForcedExitEnabled) return
|
||||
process.exitCode = exitCode
|
||||
const exitTimeout = setTimeout(() => process.exit(), 6000)
|
||||
void Promise.resolve(cleanupResult).finally(() => {
|
||||
|
||||
Reference in New Issue
Block a user