From 9649ef2514b3144752958be4e0defe450b1988bd Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Sun, 19 Apr 2026 16:43:11 +0200 Subject: [PATCH] fix: close PGlite handle after tests to resolve exit code 100 PGlite's WASM worker kept an open async handle, causing Bun to detect a resource leak and exit with code 100 despite all tests passing. Adds a preload script that closes the cached client via afterAll. Co-Authored-By: Claude Sonnet 4.6 --- bunfig.toml | 1 + tests/helpers/db.ts | 2 +- tests/setup.ts | 9 +++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/setup.ts diff --git a/bunfig.toml b/bunfig.toml index e5171ab..fadb68d 100644 --- a/bunfig.toml +++ b/bunfig.toml @@ -1,3 +1,4 @@ [test] root = "tests/" timeout = 30_000 +preload = ["./tests/setup.ts"] diff --git a/tests/helpers/db.ts b/tests/helpers/db.ts index 6a181de..4a3ca02 100644 --- a/tests/helpers/db.ts +++ b/tests/helpers/db.ts @@ -7,7 +7,7 @@ import * as schema from "../../src/db/schema.ts"; type Db = ReturnType>; // Cache: one PGlite instance per test file (per worker) -let cachedClient: PGlite | null = null; +export let cachedClient: PGlite | null = null; let cachedDb: Db | null = null; async function getOrCreateDb(): Promise { diff --git a/tests/setup.ts b/tests/setup.ts new file mode 100644 index 0000000..04283bb --- /dev/null +++ b/tests/setup.ts @@ -0,0 +1,9 @@ +// Bun test preload: close PGlite WASM worker after each file to prevent exit code 100 (leaked handles). +import { afterAll } from "bun:test"; +import { cachedClient } from "./helpers/db.ts"; + +afterAll(async () => { + if (cachedClient) { + await cachedClient.close(); + } +});