Skip to content

test: add Vitest client-side test suite + CI#21

Merged
shimoncohen merged 11 commits into
mainfrom
test/client-side-vitest-suite
Jul 21, 2026
Merged

test: add Vitest client-side test suite + CI#21
shimoncohen merged 11 commits into
mainfrom
test/client-side-vitest-suite

Conversation

@shimoncohen

Copy link
Copy Markdown
Contributor

Summary

  • Adds a Vitest + @testing-library/svelte (jsdom) harness for the client-side code (no server/S3/E2E scope).
  • 28 tests across 4 files: demoCache storage util, demoIndex JTD schema, flems.svelte editor wrapper, and the demo +page.svelte (cache banner, debounced save, clear-confirm, route-change reload).
  • +page.svelte is tested by mocking the Flems child + $app/stores + $env/dynamic/public; the real editor is never mounted.
  • Adds a test job to pull-request.yaml so the suite runs on every PR.

Notes

  • Pins @testing-library/svelte@^4 and vitest@^1 — v5 of testing-library needs Svelte 5; this repo is Svelte 3.59. The v5-only svelteTesting() plugin is replaced by resolve.conditions: ['browser'] + the @testing-library/svelte/vitest setup entry.
  • SvelteKit virtual modules ($app/stores, $env/dynamic/public) are aliased to inert stubs so Vite can transform components under the plain svelte() plugin; per-test vi.doMock supplies the real behavior.
  • Tests characterize the existing cache behavior, including two intentional drifts from the original cache design doc: saveCache stores a bare JSON array (not { files, savedAt }), and debounceMs = 0 is accepted (only NaN/negative fall back to 500).

Test Plan

  • npm run test → 28/28 pass
  • npm run check (svelte-check) → 0 errors
  • CI Run Vitest job green on this PR

🤖 Generated with Claude Code

shimoncohen and others added 10 commits July 21, 2026 12:04
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add vitest resolver aliases + inert stubs for the SvelteKit virtual
modules $app/stores and $env/dynamic/public so the page component can
be transformed under the plain svelte plugin; per-test vi.doMock
overrides them at runtime.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add ambient import so @testing-library/jest-dom matcher types reach the
type checker (runtime registration is in vitest-setup.ts, which sits
outside svelte-check's include). Pass the full PageData shape to the page
render so svelte-check accepts the fixture.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Restore mocks/globals before clearing localStorage so an SSR-guard test
that stubs localStorage to undefined cannot break teardown for later
tests. Removes the per-test unstub workaround in demoCache.test.ts.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@shimoncohen shimoncohen self-assigned this Jul 21, 2026
@shimoncohen
shimoncohen merged commit 968fc38 into main Jul 21, 2026
6 checks passed
@shimoncohen
shimoncohen deleted the test/client-side-vitest-suite branch July 21, 2026 11:08
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