Require tests
When to apply
- •Adding or changing a feature in the API (new route, new behavior) or in the web app (new component, API usage, helpers).
- •Fixing a bug (always: test first, then fix).
- •User asks for tests or mentions test coverage.
Rules
- •New feature: API — add or update integration tests in
src/api/tests/. Web — add or update unit tests insrc/web/tests/for the changed behavior. - •Bug fix: First add or adjust a test that reproduces the bug (the test must fail). Then implement the fix until the test passes. Applies to both API and web.
- •Do not mark the task done without the corresponding tests.
API tests
- •Framework: Vitest.
- •Location:
src/api/tests/*.test.ts. - •Setup:
ensureSchema()intests/setup.tsso the table exists; tests use the same DB config as the app (env vars). - •Pattern:
beforeAllbuild app and ensure schema;afterAllclose app and pool; each test usesapp.inject()and asserts onstatusCodeandres.json().
Web tests
- •Framework: Vitest.
- •Location:
src/web/tests/*.test.ts. - •Unit tests for:
api.ts(mockfetch, assert on requests and parsed response); pure helpers (e.g.formatDate,escapeHtml); any extracted logic used by Alpine components. - •Bug fix: write the failing test first, then fix the implementation.