Unit testing guidelines for passport project. Use when writing tests, creating test files, testing new code, modifying tests, understanding test patterns, ensuring test coverage.
Unit testing workflow and patterns for Passport backend.
pnpm test:unit # Run tests in watch mode (workspace)
pnpm test:unit:ci # Run tests once (workspace, CI mode)
pnpm test:typecheck # Verify TypeScript across all packages
pnpm lint # Run workspace lint checks
Run commands from the monorepo root.
Backend tests live in backend/src/**/__tests__ and use *.test.ts.
401) and admin role (403)./auth/session must return nickname and support both cookie and bearer token session lookup./auth/login must reject missing or invalid redirect values (open-redirect protection).Accept header:
application/json) receive 401 with login_required.text/html) receives redirect to /auth/login.SECURITY_STRICT_OAUTH21=true) must reject missing state/PKCE parameters and reject plain PKCE.POST/PATCH/DELETE requests.409).describe to group tests by function/moduleit for individual test casesvitest explicitly (describe, it, expect, vi, beforeEach) for consistency with existing testsdb/env in middlewareAccept headers (application/json vs text/html)toHaveLength(n) - Check string/array lengthtoBe(value) / not.toBe(value) - Strict equalitytoMatch(/regex/) - Match regex patterntoBeInstanceOf(Type) - Check instance typetoBeGreaterThan(n) / toBeLessThan(n) - Numeric comparison