WIP: test(mocks): migrate vi.mock factories to __mocks__ + test-fixtures (#560) #657
Closed
marcel
wants to merge 2 commits from
feat/issue-560-vimock-migration into main
pull from: feat/issue-560-vimock-migration
merge into: marcel:main
marcel:main
marcel:feat/issue-753-journey-editor
marcel:feat/issue-750-lesereisen-data-model
marcel:worktree-feat+issue-738-nl-search-backend
marcel:feat/issue-286-notification-bell-form-actions
marcel:feat/issue-580-sentry-backend
marcel:fix/issue-593-management-port-zero
marcel:worktree-feat+issue-557-upload-artifact-v3-pin
marcel:worktree-chore+issue-556-drop-client-branches-coverage-gate
marcel:fix/issue-514-prerender-crawl-bakes-redirects
marcel:fix/issue-472-prerender-entries
marcel:feat/issue-395-readme
marcel:feat/issue-345-bulk-mark-reviewed
marcel:feat/issue-344-bell-tooltip
marcel:feat/issue-341-annotieren-contrast
marcel:feat/issue-225-bulk-metadata-edit
marcel:feat/issue-317-bulk-upload
marcel:feat/issue-271-dashboard-redesign
marcel:docs/issue-240-mission-control-spec
marcel:refactor/issues-193-200
marcel:feat/issue-162-korrespondenz-redesign
marcel:feature/68-new-document-file-first
marcel:feat/81-discussion-discoverability
marcel:feat/62-document-bottom-panel
marcel:feature/56-backfill-file-hashes
marcel:feat/38-document-edit-history
marcel:fix/svelte5-test-delegation-and-login-auth
No Reviewers
Labels
Clear labels
P0-critical
P1-high
P2-medium
P3-later
audit
bug
cleanup
collaboration
conversation
descoped
devops
documentation
epic
feature
file-upload
legibility
needs-discussion
notification
person
phase-1: security
phase-2: container-images
phase-3: prod-compose
phase-4: spring-prod-profile
phase-5: backups
phase-6: deployment-docs
phase-7: monitoring
refactor
security
test
ui
user
Blocks a core user journey, causes data loss, or is a security/accessibility barrier. Work on this before P1+.
Significant friction on a main user journey; workaround exists but is non-obvious. Next up after P0.
Noticeable improvement; doesn't block anything; schedule opportunistically.
Cosmetic or parking-lot work; fine to stay open indefinitely.
Read-only audit / assessment work; produces a report rather than changing code
Something isn't working
Removal of dead code, vague comments, naming violations, and scratch artifacts
We want to extend the family archive to have more collaboration tools
We will do that later
README, ARCHITECTURE, GLOSSARY, CONTRIBUTING, per-domain docs
Marker for epic-level issues that group multiple child issues
Codebase Legibility Refactor — preparing the codebase for human evaluation and bus-factor reduction
Has an open decision or design question that must be resolved before implementation can start.
Security hygiene — must be done first
Production-ready multi-stage Docker images
Production compose overlay + Caddy reverse proxy
Spring Boot production configuration profile
Database and object storage backup strategy
.env.example, DEPLOYMENT.md, runbook
Prometheus, Loki, Grafana, Alertmanager
Code restructuring without behaviour change
UI/UX and accessibility issues
No Label
Milestone
No items
No Milestone
Projects
Clear projects
No project
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: marcel/familienarchiv#657
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "feat/issue-560-vimock-migration"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Implements issue #560 in incremental commits. Long-running migration; opened as draft (WIP:) for CI gating.
First commit is the load-bearing experiment: adds
__mocks__/$app/navigation.tsand migrates a single consumer (DocumentRow.svelte.spec.ts) from a factory mock tovi.mock('$app/navigation')(no factory). If CI is green, the same redirect pattern will be applied across the remaining 35$app/navigationfactories, then to$app/state,$app/forms, and the paraglide modules. Subsequent commits will follow the phase plan agreed in the implementation plan.Personas have already reviewed #560; key decisions captured:
*.test-fixture.svelteconventionsetNotifications(items)setter viaonReady@vitest/browser-playwrightexact-pin is out of scope (separate devops issue to file)Plan
__mocks__/redirects):$app/navigation→$app/state→$env/static/public→$lib/paraglide/*→$app/storespage migration + spec cleanup →$app/forms(with shared form-interceptor in the mock to cover the 4 complex consumers Felix flagged).confirm.test-fixture, then notification store context refactor + newnotification.test-fixture.sveltecovering the 2 remaining specs.Refs ADR-012. Closes #560 (on green).
Test plan
__mocks__/resolution works for SvelteKit virtual modules)no-async-mock-factories,no-duplicate-mock-ids) green throughout[birpc] rpc is closedlines in CI coverage logscoverage-flake-probe.ymltrigger before un-WIP'ing this PR🤖 Generated with Claude Code
Migrates 36 of the remaining 37 vi.mock('$app/navigation', factory) call sites in frontend/src/**/*.svelte.{spec,test}.ts to vi.mock('$app/navigation') (no factory), so they all resolve to the shared src/__mocks__/$app/navigation.ts stub introduced in commitaea37250. Special handling: - DropZone.svelte.spec.ts: removed vi.hoisted invalidateAllMock; test body now imports invalidateAll from $app/navigation and uses vi.mocked(invalidateAll) for assertions. - documents/bulk-edit/page.svelte.test.ts: removed the module-scope const gotoSpy = vi.fn() that was injected into the factory; test body now imports goto from $app/navigation and uses vi.mocked(goto) for assertions and mockClear(). Deferred: src/lib/shared/hooks/useUnsavedWarning.svelte.test.ts uses a non-trivial beforeNavigate wrapper that captures the callback into module-scope state (registeredBeforeNavigate) so tests can simulate navigation events. That hybrid factory cannot be replaced with the plain-vi.fn() shared stub without redesigning the test; it is left in place and will be addressed separately. Per ADR-012: eliminating factory bodies removes 36 birpc teardown-race surface points. The shared mock keeps every nav export as a vi.fn(). Refs #560. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>Closing without merge — empirical finding invalidates the load-bearing premise
CI run #1857 (commit
9fcd0553) failed with 2 of 274 tests:What this means
vi.mock('$app/navigation')without a factory does NOT fully replace the SvelteKit virtual module via the sharedsrc/__mocks__/$app/navigation.ts. Vitest's auto-mock substitutes some exports (e.g.gotobecomes avi.fn()— DocumentRow's tests verified that in run #1856) but leaves others bound to the real implementation (e.g.replaceStatehere). The result is partial mocking: code paths that exercise the unmocked exports hit the real router and fail.The personas (Felix, Markus, Sara, Nora, Elicit, Leonie, Tobias) and the issue body all assumed full auto-resolve via
__mocks__/. None of the reviews verified this empirically. The first commit on this PR (run #1856) only appeared to validate the approach becauseDocumentRow.svelte.spec.tshappens not to exercise the partially-mocked exports.Pivot options surfaced by the failure
Captured in follow-up discussion issue (to be filed). Three alternatives:
src/__mocks__/$app/navigation.ts, but each spec usesimport * as navMock from '$mocks/...'; vi.mock('$app/navigation', () => ({ ...navMock }));. Two lines per spec, consolidates the mock body, works because the factory is explicit. Sync factories are not banned by the meta-test (onlyasync + dynamic importis).__mocks__/plan; keep status quo of per-spec factories. The original goal in ADR-012 — preventing the birpc teardown race fromasync + dynamic importfactories — is already enforced by ESLint, CI grep, and the in-suite meta-test. Sync factories don't trigger the race. The migration in #560 would be cosmetic at best, broken at worst.resolve.alias,setupFiles-based registration, or a custom Vitest module resolver to make the redirect work. Higher complexity.Action
Refs #560.
marcel referenced this pull request2026-05-21 19:16:13 +02:00
marcel referenced this pull request2026-06-02 19:04:28 +02:00
marcel referenced this pull request2026-06-02 19:04:43 +02:00
marcel referenced this pull request2026-06-02 19:04:59 +02:00
marcel referenced this pull request2026-06-02 19:05:42 +02:00
Pull request closed