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(); + } +});