Contributor Testing
Snapshot testing is contract work. Use the nearest existing test in the same surface before inventing a new harness.
Read First
Section titled “Read First”docs/engineering-rules.mdsrc/test-setup.ts- the nearest surface
CLAUDE.md - the closest existing test file for the surface you are changing
Test Stack
Section titled “Test Stack”bun test preloads src/test-setup.ts, which installs the shared happy-dom
globals used across the repo.
Use @vitest-environment jsdom on suites that need interactive DOM behavior,
@testing-library/react, hooks, or event handling.
Use renderToStaticMarkup in component suites to prove SSR safety for the
modified surface.
Which Tests Match Which Contract
Section titled “Which Tests Match Which Contract”| Surface | What to prove | Current source-backed patterns |
|---|---|---|
| SDK bootstrap | factory defaults, auth contract, realtime bootstrap | src/create-snapshot.test.tsx, src/auth/__tests__/contract.test.ts |
| Actions and workflows | observable state and effect behavior | src/ui/actions/__tests__, src/ui/workflows/__tests__ |
| Component schema contract | accepted config, rejected config, defaults, refs, slots, states | component schema.test.ts files |
| Component runtime contract | rendered output, events, state publishing, SSR safety | component component.test.tsx files |
| SSR contract | response shape, shell injection, render chain, cache and state serialization | src/ssr/__tests__ |
| Vite and sync | plugin hooks, sync triggers, build output | src/vite/__tests__ |
| CLI and scaffold | sync output and generated template expectations | src/cli/__tests__ |
Context Helpers
Section titled “Context Helpers”For UI context tests, use AppContextProvider and PageContextProvider as
shown in src/ui/context/__tests__/providers.test.tsx.
Fastest Contributor Flow
Section titled “Fastest Contributor Flow”- Find the nearest existing test file in the same surface.
- Copy the fixture shape and wrapper pattern from that file.
- Add schema or type-level assertions first if the public contract changed.
- Add runtime assertions second for visible behavior.
- Add
renderToStaticMarkupcoverage if the change touches a component surface. - Run
bun testandbun run docs:ci.