Skip to content

test: establish a testing strategy (local fast tests + CI smoke) #4

Closed

Description

@Ardnived

Summary

We just bootstrapped testing in this repo: vitest (v2, vite-5 compatible), a
single root-page smoke test (tests/smoke/root.smoke.test.ts) that runs in
CI against the live Cloudflare Pages preview, and a preview-URL discovery script
(scripts/get-cloudflare-preview-url.mjs). That gives us a "is the deploy alive"
signal but no fast local tests and only one trivial smoke assertion.

This ticket proposes a deliberate, tiered testing strategy covering both local
fast tests
(run on every change / pre-PR) and CI (gate + smoke), so we can
grow coverage without slowing the inner loop. It is a strategy/umbrella ticket —
each tier below can become its own follow-up PR.

Current state

  • ✅ vitest installed; test:smoke script; dedicated vitest.smoke.config.ts
  • ✅ CI smoke job discovers the CF Pages preview and fetches / (asserts 200 +
    SPA shell)
  • ❌ No unit or component tests, and no test script for a fast local lane
  • ❌ CI gate is lint + typecheck + build only — no tests run on the gate
  • ⚠️ tsconfig.json has "include": ["src"], so pnpm typecheck does not
    type-check tests/** or scripts/** — test/script type errors slip through
  • ⚠️ Two entry points are untested: the embeddable widget (src/Widget.tsx,
    HashRouter) and the standalone build (src/main.tsx, BrowserRouter)

Proposed strategy (three tiers)

Tier 1 — Local fast tests (unit / logic), < ~5s

Pure, dependency-light tests that run on every change and pre-PR. High-value
targets:

  • zod schemas (src/types/*) — parse representative API fixtures (incl.
    the *Slim list variants and Client), and assert malformed payloads reject
  • geo / map helpers — turf-based math and the cluster/selection logic
    extracted from src/components/mapbox/
  • zustand stores (src/config/store.ts) — useViewState / useNavigationState
    (prev/current path) / useSearchState reducers
  • i18n (src/config/i18n.ts) — %{var} (Ruby-style) interpolation and
    locale fallback behavior
  • api layer (src/config/api/fetch.ts) — the request interceptor attaches
    Authorization + locale (mock axios)

Decision needed: component tests or node-only? WeMeditateWeb deliberately
runs node-only (no jsdom / Testing Library). Options:

  • (a) node-only logic tests + renderToStaticMarkup for presentational
    components (no jsdom)
  • (b) add jsdom + @testing-library/react for interactive component tests

Recommendation: start with (a) to keep the lane fast; add (b) only if a
component genuinely needs DOM/interaction coverage.

Tier 2 — CI gate

Add the fast lane to the PR gate so logic regressions block merge:
lint + typecheck + unit + build. Add test / test:run scripts and a
vitest.config.ts for the unit lane (separate from vitest.smoke.config.ts).

Optionally add a PostToolUse hook that runs the unit lane after editing
src/** (mirrors the sy-devs-cms "Tier 1 hook" pattern) for instant feedback.

Tier 3 — CI smoke (expand)

Grow tests/smoke/ beyond the root page, still fetch-based against the CF
preview:

  • SPA deep-link fallback — GET /search (and an entity route) returns 200,
    validating public/_redirects works on Cloudflare (guards the fix from PR chore(claude): add Claude Code config + harmonize lint/format/typecheck #3)
  • Static assets — embed.js (the widget bundle) and a public/locales/...
    JSON load with 200 + correct content-type
  • 404 / unknown asset behavior
  • Consider a Playwright smoke (1–2 specs) for actual map render / click,
    since fetch only sees the SPA shell of this client-rendered app

Cross-cutting items

  • Type-check tests & scripts: add a tsconfig that includes tests/** and
    scripts/** (or a vitest typecheck project) so they're covered by CI
  • What NOT to test: don't test NextUI / react-map-gl / library internals —
    cover our logic and contracts only
  • Fixtures: a small tests/fixtures/ of real API responses to keep schema
    tests honest against the Atlas API shape
  • Smoke discovery hardening: confirm graceful skip on forked PRs (no token)
    and tune the discovery timeout

Acceptance criteria

  • Decision recorded: component-test approach (node-only vs. jsdom + RTL)
  • Unit lane exists (vitest.config.ts + test / test:run scripts),
    separate from the smoke lane
  • At least the high-value Tier 1 targets above have unit tests (schemas,
    stores, i18n interpolation, api interceptor)
  • CI gate runs the unit lane (lint + typecheck + unit + build)
  • tests/** and scripts/** are type-checked in CI
  • Smoke suite covers the SPA deep-link fallback (/search → 200) in addition
    to the root page
  • README/CLAUDE.md + .claude/skills/pr-prep & implement-issue updated to
    reference the real test commands (they currently note "no test suite yet")

Files affected (expected)

  • vitest.config.ts (new), package.json (scripts/deps)
  • tests/unit/** (new), tests/fixtures/** (new), tests/smoke/** (expand)
  • .github/workflows/ci.yml (add unit to gate)
  • tsconfig for tests/scripts (new or adjusted)
  • Possibly .claude/hooks/ (unit-test PostToolUse hook), .claude/rules/ (a
    tests.md), and .claude/skills/{pr-prep,implement-issue}

References

  • Smoke infra added in PR chore(claude): add Claude Code config + harmonize lint/format/typecheck #3 (branch chore/claude-config):
    tests/smoke/root.smoke.test.ts, vitest.smoke.config.ts,
    scripts/get-cloudflare-preview-url.mjs, the CI smoke job
  • Tiered-testing prior art: sy-devs-cms (Tier 1 hook / Tier 2 pre-PR / Tier 3
    CI) and WeMeditateWeb (node-only vitest, fetch smoke vs. CF preview)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Hold Until

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions