Testing
Keyflare uses Vitest with the Cloudflare Workers pool for testing.Running Tests
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
@cloudflare/vitest-pool-workers.
Test Isolation
Each test run:- Creates a unique temp directory at
os.tmpdir()/keyflare-test-<pid> - Directs Miniflare’s D1 storage there via
d1Persistinvitest.config.ts - Deletes the temp directory after all tests finish
- 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 tomain and on pull requests. The workflow (.github/workflows/ci.yml) triggers only when relevant paths change.
Steps run in order:
- Install (frozen lockfile)
- Build
- Typecheck
- Lint
- Test
.nvmrc (24); pnpm is cached.
Next Steps
Development
Set up your development environment.
Architecture
Understand how Keyflare works.
