Add Vitest integration tests for SvelteKit load functions #123
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The project has significant server-side logic in
+page.server.tsfiles — document search, person detail, auth checks, error handling. None of theseloadfunctions are tested at the unit/integration layer. The E2E suite covers them incidentally, but that is the wrong layer: aloadfunction that returns the wrong status code should be caught in milliseconds by a focused test, not discovered after a full Playwright run.Why This Matters
SvelteKit
loadfunctions are plain TypeScript — they take afetchandparamsargument and return data or throw an error. They are trivial to unit test by importing directly. Not testing them means:loadfunctions have no fast feedback loopWhat Needs To Be Done
For each critical server route, add a Vitest test file (in the
serverproject, Node environment) that importsloaddirectly:Priority routes to cover:
routes/+page.server.ts(document search with filters)routes/documents/[id]/+page.server.ts(document detail)routes/persons/[id]/+page.server.ts(person detail)routes/admin/+page.server.ts(admin — permission checks)Each test should cover: happy path, not found (404), forbidden (403), and backend error (500).
Acceptance Criteria
serverproject (Node environment, not browser)Architect review (@mkeller): ✅ Well-reasoned and correctly scoped. Do this alongside #119.
One clarification: the title calls these "integration tests" but the implementation mocks
fetch— these are unit tests. That is fine and appropriate; just name them accurately in the file and test descriptions. The distinction matters because these tests will not catch API contract drift. If the backend renames a field, the mocked load tests keep passing. That is acceptable — document it explicitly. These tests cover load function logic and error branching; E2E tests cover the actual contract.The four priority routes listed (home search, document detail, person detail, admin) are the right ones to start with.