Skip to content

Commit 684e089

Browse files
committed
fix(mollifier): mock db.server in gate test to avoid eager prisma connect
The unit cascade tests in mollifierGate.test.ts import the gate module, which transitively pulls in ~/db.server. That module constructs the prisma singleton at import time and eagerly calls $connect(), which fails against localhost:5432 in the unit-test shard and surfaces as an unhandled rejection that fails the whole vitest run. Mocking the module keeps the cascade tests pure and leaves the postgresTest cases on the testcontainer-fixture prisma untouched.
1 parent d750cb1 commit 684e089

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

apps/webapp/test/mollifierGate.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1+
import { describe, expect, it, vi } from "vitest";
2+
3+
// Stub `~/db.server` before importing anything that transitively imports it.
4+
// The real module eagerly calls `prisma.$connect()` at singleton construction
5+
// (db.server.ts), so loading it under vitest tries to reach localhost:5432
6+
// and surfaces as an unhandled rejection that fails the whole shard — even
7+
// though no test in this file actually uses the default prisma client.
8+
// `postgresTest` provides its own container-backed prisma via the fixture.
9+
vi.mock("~/db.server", () => ({
10+
prisma: {},
11+
$replica: {},
12+
}));
13+
114
import { postgresTest } from "@internal/testcontainers";
2-
import { describe, expect, it } from "vitest";
315
import { FEATURE_FLAG } from "~/v3/featureFlags";
416
import { makeFlag } from "~/v3/featureFlags.server";
517
import {

0 commit comments

Comments
 (0)