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 <noreply@anthropic.com>
This commit is contained in:
@@ -7,7 +7,7 @@ import * as schema from "../../src/db/schema.ts";
|
||||
type Db = ReturnType<typeof drizzle<typeof schema>>;
|
||||
|
||||
// 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<Db> {
|
||||
|
||||
9
tests/setup.ts
Normal file
9
tests/setup.ts
Normal 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();
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user