Skip to content

Testing

Terminal window
pnpm test
pnpm typecheck
pnpm lint
pnpm build
  • pnpm test runs each workspace package’s tests, then the script tests (pnpm run test:scripts, node --test over scripts/lib).
  • API tests use Vitest with @cloudflare/vitest-pool-workers against simulated D1 and R2.
  • Admin tests use Vitest. A Playwright end-to-end suite runs with pnpm --filter @kenresoft-cms/admin e2e against its own isolated local API and database state.
  • @kenresoft-cms/astro and the create CLI use Node’s built-in test runner.

CI (.github/workflows/ci.yml) runs typecheck, lint and build everywhere. The full test suite runs on public repositories, or when the repository variable RUN_FULL_TESTS is true. CodeQL and Dependency Review run only on public repositories.

  • Windows, API tests: @cloudflare/vitest-pool-workers can fail to start once many isolated runtimes are open, which shows up as start-up timeouts or files reporting no tests. Run the API tests one file at a time with a single worker, for example pnpm --filter @kenresoft-cms/api exec vitest run test/forms-routes.test.ts --maxWorkers=1, and rerun any file that didn’t start.
  • Windows, local D1: wrangler dev or wrangler d1 can fail with an internal error when the persisted state sits under a long path. Pass a short --persist-to, such as C:/kd1.
  • Rate-limit tests: Workers rate-limit bindings count in fixed windows aligned to the clock, so a test that sends limit + 1 requests fails if it happens to cross a window boundary. Call startInFreshRateLimitWindow() from apps/api/test/helpers/rate-limit.ts right before the burst.
  • R2 in tests: read or cancel every R2 object body you fetch in a test (for example await object.arrayBuffer()). An unread body makes the test pool report “Isolated storage failed”.
  • Simulating failures: vi.mock doesn’t reliably replace the API’s own modules in the Workers test pool. To test a failure path, pass a wrapped R2Bucket or database that throws, as apps/api/test/form-submission-storage.test.ts does.
  • Admin tests: Vitest hands onUnhandledError a serialized error, a plain object, so match it by name, never instanceof.

Test a new starter project, an existing project, a project with custom pages, re-running the installer, updating an untouched and a modified managed file, and a Cloudflare deployment.