Skip to content

Contributor Testing

Snapshot testing is contract work. Use the nearest existing test in the same surface before inventing a new harness.

  1. docs/engineering-rules.md
  2. src/test-setup.ts
  3. the nearest surface CLAUDE.md
  4. the closest existing test file for the surface you are changing

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.

SurfaceWhat to proveCurrent source-backed patterns
SDK bootstrapfactory defaults, auth contract, realtime bootstrapsrc/create-snapshot.test.tsx, src/auth/__tests__/contract.test.ts
Actions and workflowsobservable state and effect behaviorsrc/ui/actions/__tests__, src/ui/workflows/__tests__
Component schema contractaccepted config, rejected config, defaults, refs, slots, statescomponent schema.test.ts files
Component runtime contractrendered output, events, state publishing, SSR safetycomponent component.test.tsx files
SSR contractresponse shape, shell injection, render chain, cache and state serializationsrc/ssr/__tests__
Vite and syncplugin hooks, sync triggers, build outputsrc/vite/__tests__
CLI and scaffoldsync output and generated template expectationssrc/cli/__tests__

For UI context tests, use AppContextProvider and PageContextProvider as shown in src/ui/context/__tests__/providers.test.tsx.

  1. Find the nearest existing test file in the same surface.
  2. Copy the fixture shape and wrapper pattern from that file.
  3. Add schema or type-level assertions first if the public contract changed.
  4. Add runtime assertions second for visible behavior.
  5. Add renderToStaticMarkup coverage if the change touches a component surface.
  6. Run bun test and bun run docs:ci.