test(social): note the shared-state harness contract

Per code-review suggestion: add a brief comment explaining why
module-level sqlite/testDb/app reassignment works (mock getter
closes over the current binding) and what would break it
(top-level it, .concurrent describe). Prevents a future foot-gun.
This commit is contained in:
Jannis Braun
2026-04-25 19:17:50 +02:00
parent 5f5590a3c9
commit b5b48e407e
@@ -13,6 +13,12 @@ setWorkerId(1);
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// Module-level mutable state. Each describe's beforeEach reassigns
// `sqlite`/`testDb`/`app`; the `getDb: () => testDb` getter in the mock
// closes over the current binding, so reassignment is observed. Adding
// a top-level `it` (outside any describe) or switching to `.concurrent`
// would break this pattern — keep new tests inside a describe block
// that owns its own beforeEach reset.
type TestDb = ReturnType<typeof drizzle<typeof schema>>;
let sqlite: Database.Database;
let testDb: TestDb;