Skip to content

Improve test coverage and fix component testing infrastructure#116

Open
Amadou-dot wants to merge 1 commit into
mainfrom
claude/improve-test-coverage-zdqj49
Open

Improve test coverage and fix component testing infrastructure#116
Amadou-dot wants to merge 1 commit into
mainfrom
claude/improve-test-coverage-zdqj49

Conversation

@Amadou-dot

Copy link
Copy Markdown
Owner

Summary

  • Fixed the root cause blocking component tests: framer-motion's real animation loop recurses infinitely under jsdom (any HeroUI component OOMs the test process). It's now mocked globally in jest.setup.jsdom.ts, un-blocking the four component suites that were silently excluded from jest.config.js.
  • Split the node Jest project into unit (pure functions, no DB, <1s) and integration (MongoDB Memory Server). Added test:unit, test:integration, and test:fast (unit + jsdom, no mongod binary needed) scripts.
  • Added ~180 new test cases targeting previously uncovered/low-coverage code: utils/ (was 0%), types/errors, lib/logger, requireApiAuth, lib/clerk-users batch fetching, and mutation hooks for bookings/customers/settings (was 21–26%, now ~89% for hooks overall).
  • Repaired and relocated the four legacy component suites (error, PrintBooking, AddExperienceForm x2) to __tests__/components/ — they'd drifted from the current component code (e.g. error.tsx now uses router.push instead of window.location).
  • Fixed one pre-existing failing test in experience.test.ts that predated a schema change making includes/available required non-empty arrays.

Unrelated but necessary: Prettier-formatted 4 files that were previously committed unformatted (app/api/bookings/route.ts, app/api/cron/seed/route.ts, lib/validations/experience.ts, __tests__/integration/api/cron-seed.test.ts) so pnpm ci:check passes cleanly. Formatting only, no logic changes.

Test plan

  • pnpm test:fast (unit + jsdom) — 568/568 passing
  • pnpm lint — clean
  • pnpm format:check — clean
  • pnpm check:types — no errors
  • pnpm test:integration locally — could not run in this sandbox (network policy blocks the MongoDB Memory Server binary download); only touched integration files were formatting, so no behavioral changes expected, but worth a local confirmation run

Generated by Claude Code

…ration projects

Testing infrastructure:
- Fix framer-motion under jsdom: the real animation loop recursed until the
  test process ran out of memory, which is why the four root-level component
  test suites were excluded from jest.config.js. framer-motion is now mocked
  globally in jest.setup.jsdom.ts (motion.*/m.* render as plain tags), so any
  HeroUI component can be rendered in tests. The mock moved from
  __tests__/__mocks__/ to __tests__/setup/ because Jest's manual-mock
  resolution made it require itself.
- Split the node Jest project into "unit" (pure functions, no DB, <1s) and
  "integration" (MongoDB Memory Server). New scripts: test:unit,
  test:integration, and test:fast (unit + jsdom, no mongod binary needed).
- Add utils/ and types/ to coverage collection.

Test fixes:
- Un-exclude and repair the legacy component suites: error.test.tsx asserted
  window.location navigation but app/error.tsx uses router.push now;
  PrintBooking assertions drifted from the template markup; the two
  AddExperienceForm suites were consolidated into one that matches the
  current component. All moved into __tests__/components/.
- Update experience validation test for the stronger schema (#103): includes/
  available are now required non-empty, so the "applies defaults" case was
  split into defaults-that-remain and required-array assertions.
- Remove __tests__/test-utils.tsx (trivial passthrough only used by a
  deleted suite).

New tests (+~180 cases, 568 passing in unit+jsdom):
- utils/utilityFunctions and utils/bookingUtils (previously 0%)
- types/errors type guards
- lib/logger dev/prod/test behavior
- lib/api-utils requireApiAuth (testing bypass, 401/403, error path)
- lib/clerk-users batch fetching: caching, 404-vs-transient error
  classification, concurrency limit
- Mutation hooks for bookings, customers, and settings (mutationFn payloads,
  error propagation, cache invalidation, toasts)

Unrelated-but-necessary: prettier-formatted 4 files that were committed
unformatted on main (app/api/bookings/route.ts, app/api/cron/seed/route.ts,
lib/validations/experience.ts, __tests__/integration/api/cron-seed.test.ts)
so ci:check passes. Formatting only, no logic changes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PbLP4qpeRszHTtgavQFB2L
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