fix: close PGlite handle after tests to resolve exit code 100
All checks were successful
CI / ci (push) Successful in 1m40s
CI / e2e (push) Has been skipped
CI / deploy (push) Successful in 58s

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 <noreply@anthropic.com>
This commit is contained in:
2026-04-19 16:43:11 +02:00
parent 5f63e6f75d
commit 9649ef2514
3 changed files with 11 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
[test] [test]
root = "tests/" root = "tests/"
timeout = 30_000 timeout = 30_000
preload = ["./tests/setup.ts"]

View File

@@ -7,7 +7,7 @@ import * as schema from "../../src/db/schema.ts";
type Db = ReturnType<typeof drizzle<typeof schema>>; type Db = ReturnType<typeof drizzle<typeof schema>>;
// Cache: one PGlite instance per test file (per worker) // 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; let cachedDb: Db | null = null;
async function getOrCreateDb(): Promise<Db> { async function getOrCreateDb(): Promise<Db> {

9
tests/setup.ts Normal file
View File

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