Running unit tests
test-results/unit-coverage/ (HTML + lcov) and JUnit XML to test-results/unit-results.xml.
What’s tested
Coverage is collected from
src/lib/**/*.ts and src/scripts/**/*.ts only. Test files, type declarations, and mock data directories are excluded.
File locations
tests/integration/**/*.test.ts via the include glob in vitest.config.ts.
vitest.config.ts
Key patterns
sanity:client mock
Vitest aliases thesanity:client virtual module (an Astro/Sanity internal) to a hand-written mock at src/lib/__tests__/__mocks__/sanity-client.ts. This allows GROQ query tests to run without a live Sanity project or network access.
jsdom environment
DOM-dependent tests (client-side scripts, middleware cookie parsing) annotate with the jsdom environment pragma:Path aliases
@/ resolves to astro-app/src/ in test files, matching the same alias used in Astro’s tsconfig.json:
Example: utility test
Example: middleware test
The middleware test file (src/__tests__/middleware.test.ts) covers the unified auth routing layer — public route pass-through, portal/student session validation, KV cache hits/misses, Durable Object rate limiting, and dev mode bypass: