fix: skip beforeunload handler in test environment

The static cleanup handler was interfering with test lifecycle,
causing the server to be killed during database migration.
Skip registration when VITEST environment variable is set.
This commit is contained in:
Gerkinfeltser
2026-02-19 11:09:55 -06:00
committed by Mateusz Tymek
parent 427f0d5132
commit 1ee91fcc2f

View File

@@ -78,7 +78,8 @@ export class WindowsProcess implements OpenCodeProcess {
}
// Register beforeunload handler for window close cleanup
if (typeof window !== "undefined") {
// Skip in test environment to avoid interfering with test lifecycle
if (typeof window !== "undefined" && !process.env.VITEST) {
window.addEventListener("beforeunload", () => {
if (WindowsProcess.currentProcess?.pid) {
WindowsProcess.killProcessSync(WindowsProcess.currentProcess.pid);