Skip to content

test: stand up Vitest rig + adjacent coverage for audited surface#38

Open
nx-thaddeusaid wants to merge 28 commits intoBattletechModders:mainfrom
nx-thaddeusaid:test-platform
Open

test: stand up Vitest rig + adjacent coverage for audited surface#38
nx-thaddeusaid wants to merge 28 commits intoBattletechModders:mainfrom
nx-thaddeusaid:test-platform

Conversation

@nx-thaddeusaid
Copy link
Copy Markdown

Summary

  • Stands up a Vitest + React Testing Library + jsdom rig on a dedicated test-platform branch, branched from aca800c per session-scoped instructions (diverges from current main tip — reviewers will see the five security-patch commits as missing from the base; re-target or rebase before merge if that is unacceptable).
  • Adds 26 adjacent [name].test.ts(x) suites covering every audited source file — helpers, hooks, components, and bootstrap — yielding a green baseline of 29 files / 122 tests with yarn test.
  • Documents every decision in model/log.md (action / alternatives / reasoning, per-section).

Notable pieces

  • Rig commit (eba39d0): Vitest config pinned to jsdom + @vitejs/plugin-react-swc; src/test/setup.ts with @testing-library/jest-dom/vitest plus a Map-backed localStorage polyfill to work around Vitest 4's empty-object stub under Node 25; reusable src/test/konvaMocks.tsx that useImperativeHandle-exposes the Konva methods effects call; dedicated tsconfig.vitest.json. Relocates the three pre-existing gm.*.test.ts files from tests/ to sit adjacent to their source per CLAUDE.md's placement rule.
  • Tests commit (97a4a51): adjacent suites for every source file in the audit (helpers with edge/contract cases; hooks with renderHook + stubbed fetch + queue-based rAF; components under MemoryRouter / createMemoryRouter; Konva consumers as smoke tests behind the shared mock; main.tsx verified via a wrapped createRoot).

Scope posture

This is Option B from the session's three-option plan: deep coverage on pure utilities, hooks, and non-Konva components; smoke coverage on Konva render paths (GalaxyMap.tsx, StarSystem.tsx, useGalaxyViewport, usePinchZoom). Canvas-accurate assertions were explicitly deferred as a second-pass investment.

Test plan

  • yarn install
  • yarn test — expect 29 files / 122 tests passing
  • npx tsc -p tsconfig.vitest.json --noEmit — expect clean
  • yarn build — expect production build succeeds
  • Review model/log.md for the full decision trail

🤖 Generated with Claude Code

dobettertech and others added 28 commits November 17, 2025 09:11
Introduce the test-platform branch's working test rig: Vitest configured
with jsdom + @vitejs/plugin-react-swc, a setup file that installs
@testing-library/jest-dom and a Map-backed localStorage polyfill to work
around Vitest 4's empty-object stub under Node 25, dedicated
tsconfig.vitest.json, and reusable Konva / react-konva mocks under
src/test/. Also relocates the three pre-existing gm.* tests from tests/
to sit adjacent to their source files per CLAUDE.md's placement rule and
seeds model/log.md with the decision trail. The next commit adds the
adjacent test suites for the rest of the codebase.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Layer 26 new adjacent test files on top of the rig commit, covering every
file in the Option-B audit:

- Helpers: ApiHelper, CapitalHelper, FactionHelper, NewTabHelper,
  RouteHelper, devStateInjector, and the barrel index each get
  positive-path, edge-case, and contract coverage.
- Hook tier: useSettings, useTooltip, useWarmapAPI, useFiltering use
  renderHook + stubbed fetch; useGalaxyViewport and usePinchZoom use
  queue-based rAF plus a controllable performance.now() to deterministically
  pin throttle, zoom-clamp, pinch-start/end, and frame-coalescing behavior.
- Component tier: PageTemplate, SideMenu, Home (with HomeCard), ToS (with
  BulletPoint), and Error (all three route-error branches) run under
  MemoryRouter / createMemoryRouter. BottomFilterPanel drives toggle,
  search, faction chips, and mobile help tooltip.
- Konva smoke tier: StarSystem, GalaxyMap, App, and main.tsx bootstrap run
  against the shared src/test/konvaMocks reusable mock, with fetch stubbed
  to produce valid faction/system payloads; main.tsx wraps createRoot to
  confirm the bootstrap attaches to #react-root.
- Pages barrel: pages/index.test.ts re-export contract.
- Types: Settings.test.ts exercises initialSettings; hooks/types/index
  expectTypeOf-asserts the full type-alias surface so every type file is
  covered under the adjacent convention.

Final suite: 29 files / 122 tests passing. `yarn build` and
`npx tsc -p tsconfig.vitest.json --noEmit` both clean.

Updates model/log.md with sections 8 (authoring strategy per tier) and 9
(final rig verification + coverage map).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…mbers

The `test:coverage` script already existed but was unreachable without a
provider installed. Pin `@vitest/coverage-v8` to `4.0.8` to match Vitest's
version (4.1.x ships an import against `vitest/node` that 4.0.x does not
export), configure text/html/lcov reporters with reasonable include /
exclude globs, and add `coverage/` to `.gitignore` so generated reports
don't dirty the working tree.

Initial report: 73.9% stmts · 61.21% branches · 70.52% funcs · 76.75%
lines — deep-tested surface at 100%, the Option-B smoke targets
(GalaxyMap.tsx, StarSystem.tsx, usePinchZoom.ts) account for the gap,
matching the documented posture.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds .github/workflows/test.yml that runs on push to main / test-platform
and on any PR to main. Steps: checkout, setup-node with yarn cache, yarn
install --frozen-lockfile, tsc --noEmit against tsconfig.vitest.json,
yarn test:coverage, and an upload of the coverage/ directory as a
14-day-retention artifact (Node 20 leg only). Matrix covers Node 20 + 22.

The workflow only becomes active for PR checks on the upstream repo once
this branch merges; until then, the fork's own Actions trigger on each
push, providing a pre-merge smoke.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Moves the inline helper bodies out of GalaxyMap.tsx and StarSystem.tsx
into adjacent modules (GalaxyMap.helpers.ts, StarSystem.helpers.ts) and
rewires the two components to call them:

- StarSystem.helpers.ts: buildControlItems, formatControlLine,
  formatSystemState, formatDamageLevel, buildTooltipText.
- GalaxyMap.helpers.ts: getViewportSize, getTooltipFontSize,
  getDesktopLineSegments (now takes a {titleFontSize, bodyFontSize}
  object), and parseMobileTooltipData.

The production behavior is unchanged — two Konva call sites retain their
prior shape via a tiny segmentsFor closure, and buildTooltipText is now
called with an explicit {system, factions[, includeTapHint]} object.
31 new deep tests cover positive paths, empty inputs, ordering, label-
split branches, and the mobile parser's control-block skipping.

Suite: 31 files / 153 tests passing (was 29 / 122). Coverage across the
project: 79.22% stmts / 69.5% branches / 76.16% funcs / 82.43% lines
(was 73.9 / 61.21 / 70.52 / 76.75). The remaining gap lives inside the
Konva render trees, matching the documented Option-B posture.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@nx-thaddeusaid nx-thaddeusaid marked this pull request as ready for review April 23, 2026 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants