From 92cb048a7a1d86d85c019a340f3183ac36850017 Mon Sep 17 00:00:00 2001 From: syntaxbullet Date: Tue, 6 Jan 2026 17:22:43 +0100 Subject: [PATCH] test: fix mock leakage in db tests --- src/lib/db.test.ts | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/lib/db.test.ts b/src/lib/db.test.ts index 242d0c1..ff29601 100644 --- a/src/lib/db.test.ts +++ b/src/lib/db.test.ts @@ -1,18 +1,5 @@ import { describe, it, expect, mock, beforeEach } from "bun:test"; -// Mock shutdown module before importing db -mock.module("./shutdown", () => { - let shuttingDown = false; - let transactions = 0; - return { - isShuttingDown: () => shuttingDown, - setShuttingDown: (v: boolean) => { shuttingDown = v; }, - incrementTransactions: () => { transactions++; }, - decrementTransactions: () => { transactions--; }, - getActiveTransactions: () => transactions, - }; -}); - // Mock DrizzleClient mock.module("./DrizzleClient", () => ({ DrizzleClient: { @@ -21,11 +8,15 @@ mock.module("./DrizzleClient", () => ({ })); import { withTransaction } from "./db"; -import { setShuttingDown, getActiveTransactions } from "./shutdown"; +import { setShuttingDown, getActiveTransactions, decrementTransactions } from "./shutdown"; describe("db withTransaction", () => { beforeEach(() => { setShuttingDown(false); + // Reset transaction count + while (getActiveTransactions() > 0) { + decrementTransactions(); + } }); it("should allow transactions when not shutting down", async () => {