audit: factory mocks → prop injection migration (sveltest pattern) #554
Reference in New Issue
Block a user
Delete Branch "%!s()"
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?
Context
Follow-up from #553 / ADR-012. The fix in #553 closes the two named birpc-race triggers (async factory body, duplicate ID across spellings). It does not address the underlying ergonomics question: every
vi.mock(module, factory)in browser mode is a class of birpc race we can't hit if it doesn't exist.Familienarchiv currently has ~92 factory-style
vi.mockcalls acrosssrc/**/*.svelte.{spec,test}.ts. The ecosystem trend — verified against sveltest, the official SvelteKit basics smoke, and Scott Spence's reference guide — is fewer mocks, more prop injection / test-host wrappers. We already have one canonical example in the repo:confirm.test-host.svelte.Scope
Audit only. Produce a report; do not migrate.
For each of the ~92 factory
vi.mockcall sites:Classify into one of:
$props()field, with a default that matches today's import. Mirrorsconfirm.test-host.svelte. Best fit for domain services.__mocks__/redirect candidate — a stable, never-changing fake that lives next to the source. Best fit for SvelteKit virtual modules ($app/state,$env/static/public) and pure utility modules.Tally the result. Output: a table of
file → mocked module → classification → rationale, plus a summary count per class.Propose a roadmap. Recommend an order — typically (a) first, since each migration removes one route handler and one cleanup slot; (b) second, since it consolidates many duplicate factories; (c) is the residual.
Non-goals
docs/audits/, not code changes.Acceptance
docs/audits/<date>-vi-mock-migration-audit.mdexists onmainvi.mockcall site insrc/**/*.svelte.{spec,test}.tsis classifiedReferences
frontend/src/lib/shared/services/confirm.test-host.svelte— canonical prop-injection example in this repoapps/website/src/lib/components/nav.svelte.test.tsshows the test-host pattern at scaleAudit complete. Report filed as #560.
Results: 87 in-scope call sites across 12 mocked modules — 72 →
__mocks__/redirect, 10 → prop-injection, 5 → keep as factory. Full classification table and migration roadmap (~5 days total) in the linked issue.