test: consolidate duplicated live-query test harness - #162
Open
mbret wants to merge 1 commit into
Open
Conversation
The reactivity and unmount test suites each rebuilt the same live-query scaffold (BehaviorSubject pair + filter/switchMap/map queryFn + data span component + render) in every test — 10 copies across the two files. Extract the source into createLiveQuerySource in tests/liveQuery and collapse the per-test scaffolding into one setup helper per file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Consolidation: live-query test harness (net −162 LOC)
What was duplicated
src/lib/queries/useQuery$.reactivity.test.tsx(6 copies)src/lib/queries/useQuery$.unmount.test.tsx(4 copies)Every test in these two suites rebuilt the exact same scaffold by hand:
plus, in the unmount suite, the same
Host/togglevisibility wrapper repeated in all 4 tests, and the sameexpect(screen.getByTestId("data").textContent).toBe(JSON.stringify(...))assertion everywhere.What it became
createLiveQuerySource(initialItems)insrc/tests/liveQuery.tsx— the shared home these suites already import from (createQueryClient,createWrapper,liveQueryOptionswere consolidated there by test: dedupe isDefined helper against the library util #144's follow-ups). It builds theliveQuery$/db$pair and thefilter → switchMap → mapqueryFn that emulates a live database query.setup()helper per suite (component shape differs: plain component vs. hide/show host), plus a localexpectDataassertion helper.Why they are truly the same concept
All 10 copies exercise the same fixture — "a live query backed by a db-readiness gate that re-emits a fresh array on every push" — against the same rendered output. They were copy-pasted, differing only in query key, initial items, and (in two tests) query options, which are now plain parameters. No behavior changes: query keys, options (including the two tests that intentionally omit
staleTime: Infinity), emission sequences, timings, and assertions are byte-for-byte equivalent, and the two-observers test keeps its bespoke double-hook component.Gates (same commands CI runs, all green before and after; 139/139 tests pass both times)
npm run checknpm run build(tsc + vite)npm run test:ciOther candidates surveyed and rejected
useSwitchMutation$/useConcatMutation$: shared adapters were already extracted (mutationOptions.ts); the remaining similarity is genuinely divergent cancellation semantics (abort vs. ready-gate).createLocalStorageAdapter/createLocalforageAdapter: superficially similar JSON (de)serialization but different backends with intentionally differentremoveItem/clearsemantics.persistSignals.test.ts,useObserve.compare.test.tsx,useSwitchMutation$.test.tsx) are small intra-file test-case variations; consolidating them would trade readability for little LOC — possible future runs if they grow.🤖 Generated with Claude Code
https://claude.ai/code/session_015zuCUHEHA1tWwYQ28x4rgB
Generated by Claude Code