Skip to main content

Testing

Keyflare uses Vitest with the Cloudflare Workers pool for testing.

Running Tests

Only the server package has tests today. The cli and shared packages use vitest run --passWithNoTests, so they exit 0 when there are no test files.

Test Environment

Tests run entirely inside a Miniflare Worker runtime:
  • No network calls
  • No Cloudflare account needed
  • Full D1 support
The server uses Vitest 3.2.x with @cloudflare/vitest-pool-workers.

Test Isolation

Each test run:
  1. Creates a unique temp directory at os.tmpdir()/keyflare-test-<pid>
  2. Directs Miniflare’s D1 storage there via d1Persist in vitest.config.ts
  3. Deletes the temp directory after all tests finish
This means:
  • Tests never pollute the real local dev .wrangler/state/
  • Multiple test runs in parallel don’t collide
  • Zero artifacts left after the suite

Migrations in Tests

vitest.config.ts reads Drizzle migration files at startup via readD1Migrations() and passes them to Miniflare as a binding (TEST_MIGRATIONS). The beforeAll hook in api.test.ts calls applyD1Migrations(env.DB_BINDING, env.TEST_MIGRATIONS) to apply them before any test runs. New migrations are picked up automatically — no test code changes needed when the schema changes.

Test Files

Writing Tests

Basic Structure

Testing Auth

Testing Scopes

CI

GitHub Actions runs on every push to main and on pull requests. The workflow (.github/workflows/ci.yml) triggers only when relevant paths change. Steps run in order:
  1. Install (frozen lockfile)
  2. Build
  3. Typecheck
  4. Lint
  5. Test
Node is set from .nvmrc (24); pnpm is cached.

Next Steps

Development

Set up your development environment.

Architecture

Understand how Keyflare works.