Testing & CI
Unit tests
Unit and integration tests use Vitest and live alongside the source they cover (e.g. tax.ts → tax.test.ts). There are ~183 tests.
# Run all tests once
pnpm test
# Watch mode during development
pnpm test:unitMost tests cover pure functions — price formatting, tax calculation, shipping rules, promotion logic, cart/wishlist cookies, order utilities. Some are DB-backed integration tests that run against a real migrated in-memory SQLite database: they mock $env/dynamic/private to point the db seam at :memory:, then createNodeDb runs the full drizzle/ migration chain (FTS table, seed defaults, stock triggers) so assertions hit real SQL.
vi.mock("$env/dynamic/private", () => ({ env: { DATABASE_URL: ":memory:" } }));
import { db } from "../db/index.js";End-to-end tests
E2E tests use Playwright and live in e2e/. pnpm test:e2e boots its own dev server (on a dedicated port) unless BASE_URL is set.
# Boots its own server
pnpm test:e2e
# Against an already-running server
BASE_URL=http://localhost:5173 pnpm test:e2eLogging
Server-side logging uses console.error in hooks.server.ts. The handleError hook catches uncaught errors, assigns a unique errorId, and logs structured context (URL, method, stack trace) before returning a generic message to the client.
// hooks.server.ts
export const handleError: HandleServerError = async ({ error, event, status, message }) => {
const errorId = crypto.randomUUID();
console.error("[error]", { id: errorId, status, url: event.url.pathname, error });
return { message: "An unexpected error occurred", errorId };
};On the Cloudflare target, Workers observability is enabled in wrangler.jsonc, so logs are available in the Cloudflare dashboard.
CI workflows
Three GitHub Actions workflows run on pull requests to main. All use pnpm and Node 22.
| Workflow | File | Purpose |
|---|---|---|
| CI | .github/workflows/ci.yml | Lint (pnpm lint) + type check (pnpm check), then a build matrix over both targets (node and cloudflare) |
| Unit Tests | .github/workflows/unit-tests.yml | Runs pnpm test |
| E2E Tests | .github/workflows/e2e.yml | Seeds a throwaway SQLite database, then runs Playwright |