Skip to content

Testing

MountSQLI tests prefer the real driver for integration and MockDriver for plan-level unit tests.

MockDriver returns canned rows and lets you assert on the compiled plan — no database needed:

import { MockDriver } from "@mountsqli/driver";
import { tableQuery } from "@mountsqli/query";
import { compilePlan } from "@mountsqli/compiler";
const driver = new MockDriver();
const q = tableQuery(driver, users).where("age", ">", 18);
expect(compilePlan(q._plan).sql).toBe('SELECT * FROM "users" WHERE "age" > ?');

Use node:sqlite for real behavior:

import { mountsqli } from "@mountsqli/core";
import "@mountsqli/driver-sqlite";
const db = mountsqli({ driver: "sqlite", url: ":memory:", tables: [users] });
await db.from(users).insert({ email: "a@b.c" });
expect(await db.from(users).findOne()).not.toBeNull();

Postgres is tested by injecting a fake Pool so no real database is needed:

const driver = new PostgresDriver({ pool: fakePool });
// fakePool implements query() returning canned rows

This verifies $N translation and borrow() concurrency without a server.

Terminal window
pnpm --filter @mountsqli/core test
pnpm --filter @mountsqli/query test
pnpm --filter @mountsqli/auth test
  • Use MockDriver for plan-shape assertions (fast, deterministic).
  • Use real node:sqlite for integration of decode/type behavior.
  • Inject a fake pool for driver-specific tests (no external DB).
  • Asserting on compiled SQL instead of the plan (brittle across dialects).
  • Forgetting :memory: resets per test file.