test: consolidate duplicated live-query queryFn into a shared helper#144
Open
mbret wants to merge 1 commit into
Open
test: consolidate duplicated live-query queryFn into a shared helper#144mbret wants to merge 1 commit into
mbret wants to merge 1 commit into
Conversation
The live-query test suites (useQuery$.reactivity and useQuery$.unmount)
repeated the exact same Observable queryFn pipe in 10 places:
db$.pipe(
filter(isDefined),
switchMap(() => liveQuery$),
map((items) => [...items]),
)
Extract it into `createLiveQueryFn` in the shared test helper so both
suites build it the same way. Also drop the local `isDefined` copy in
liveQuery.tsx, which duplicated the library's `isDefined` util, and
source it from `../lib/utils/isDefined` instead.
Behavior-preserving: the generated queryFn and its emissions are
identical; only the call sites changed.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PMgtP4GREPoEq9LdTBcHky
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.
Summary
A behavior-preserving consolidation of duplicated live-query test scaffolding, in the same spirit as #137. All gates pass (biome
check,tsc,vite build,vitest run— 129 tests).Consolidation 1 — repeated live-query
queryFnpipeWhat was duplicated: the identical Observable
queryFnpipe appeared 10 times acrosssrc/lib/queries/useQuery$.reactivity.test.tsx(6×) andsrc/lib/queries/useQuery$.unmount.test.tsx(4×):What it became: a single
createLiveQueryFn(db$, liveQuery$)helper in the sharedsrc/tests/liveQuery.tsx, invoked at every call site asqueryFn: createLiveQueryFn(db$, liveQuery$).Why they're the same concept: every live-query suite models the same shape — a
db$gate that must be defined before the query yields, feeding aliveQuery$list whose latest items are emitted. The pipe was byte-identical in all 10 sites; only the surroundingqueryKeyand assertions differ, and those stay inline.Consolidation 2 — duplicated
isDefinedWhat was duplicated:
src/tests/liveQuery.tsxdefined its ownisDefinedtype-guard, a reimplementation of the library'ssrc/lib/utils/isDefined.ts(runtime-identical null/undefined check).What it became: the test helper now imports
isDefinedfrom../lib/utils/isDefined(and re-exports it to keep the module's surface stable). The local copy is deleted.Why they're the same concept: both are the "value is not null/undefined" guard; there is no reason for the test tree to carry a second implementation.
Net LOC
34 insertions, 67 deletions→ net −33 lines across 3 files.Notes / opportunities left for a future sweep
Hosttoggle harness (let toggle+useStatevisibility wrapper) is repeated 4× inuseQuery$.unmount.test.tsx, but each copy closes over a locally-definedListcomponent, so extracting it cleanly needs a small factory and was left out to keep this PR's story tight.🤖 Generated with Claude Code
Generated by Claude Code