Skip to content

Testing

Terminal window
bun run test # every package
bun run --filter @cemco/api test # one package
cd workers/api && bunx vitest run test/orders.test.ts # one file

Worker tests use Vitest with @cloudflare/vitest-plugin (the successor of @cloudflare/vitest-pool-workers, which does not support Vitest 5). Tests run inside workerd, the same runtime as production, with real local bindings:

  • workers/api: a real local D1. test/setup.ts applies the migrations; storage is isolated per test file. The AUTH binding is a stub: header x-cemco-dev-user: <email> signs in, and x-api-key: test-<role> is an API key with that role.
  • workers/web: stub ASSETS, API, AUTH and AGENTS bindings that echo what they receive, to test host routing, proxying (including WebSocket upgrades) and headers.

Keep remoteBindings: false in every Vitest config; otherwise the AI binding asks for a Cloudflare login.

workers/api/test/helpers.ts has what you need:

import { beforeAll, expect, it } from "vitest";
import { actorByEmail, callOp, callOpError, seedDatabase, SEED } from "./helpers";
beforeAll(seedDatabase);
it("blocks an order that is not valid", async () => {
const editor = await actorByEmail(SEED.editor);
const order = await callOp(editor, "orders.list", { stage: "received", valid: false });
const error = await callOpError(editor, "orders.advance", { id: order.items[0]!.id });
expect(error.code).toBe("invalid_order");
});
  • callOp(actor, name, input, { now? }) takes the same path as HTTP and RPC, with the clock fixed at 2026-12-06T15:00Z.
  • auditRows(name) returns the audit rows an operation wrote.
  • SEED.admin, editor, viewer, customer and otherCustomer are the seed logins.

Every rule in the architecture has a test, and every portal operation is tested with a second customer to prove they cannot see the first customer’s data.

  • packages/core: schemas, rules and the registry (pure Vitest).
  • packages/ui: a hash check that the Rapport kit files are unchanged.
  • apps/docs: the data model and API reference generators against the real migrations and catalog.

.github/workflows/ci.yml runs on every pull request: bun install --frozen-lockfile, lint, build, typecheck, test. Keep it green.