test: consolidate duplicated live-query test helpers#137
Merged
Conversation
The `useQuery$.reactivity` and `useQuery$.unmount` specs each carried a byte-identical 38-line preamble (isDefined, createQueryClient, liveQueryOptions, createWrapper). Extract the shared helpers into src/tests/liveQuery.tsx and import them in both specs. No behavior change: the helpers are moved verbatim. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01U7gH7fnCjWFBRgC15JrYtA
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.
Live-query test helpers
What was duplicated.
src/lib/queries/useQuery$.reactivity.test.tsxandsrc/lib/queries/useQuery$.unmount.test.tsxeach carried a byte-identical 38-line preamble before theirdescribeblock:isDefined<T>()— narrowing guardcreateQueryClient()— aQueryClientwithgcTime: 0liveQueryOptions— the{ networkMode: "always", gcTime: 0, staleTime: Infinity }option blockcreateWrapper(queryClient)— theQueryClientProvider/QueryClientProvider$wrapperThis was the single largest clone flagged by
jscpd(a 38-line exact match between the two files).What it became. The four helpers now live in a new shared module
src/tests/liveQuery.tsx(next to the existingsrc/tests/utils.tsx), imported by both specs. The code is moved verbatim — sameQueryClientconfig, same option values, same wrapper JSX — so behavior is unchanged. The now-unused@tanstack/react-query,reacttype, andQueryClientProvider$imports were dropped from both specs (the repo compiles withnoUnusedLocals).Net LOC delta: +45 / −66 = −21 lines.
Why these are truly the same concept. The two blocks are byte-for-byte identical (verified with
diff), not merely similar — they are the shared scaffolding for the live-queryuseQuery$specs. Only these two files defined these helpers; the other query specs use genuinely different inline setups (plainnew QueryClient(),PersistQueryClientProvider, customclientprops), so they were intentionally left untouched rather than force-fitted.Gates
Run locally against a clean baseline (both before and after — identical results):
npm run check(biome) ✓npm run build(tsc + vite) ✓npm run test:ci— 22 files / 128 tests passing ✓Other candidates seen (deferred)
While sweeping I noted a
typeof x === "function" ? x(arg) : x"resolve an Observable-or-factory source" idiom repeated inuseMutation$,useSwitchMutation$,useConcatMutation$,createObservableQueryFn, anduseObserve/store. It's genuinely one concept, but a shared helper comes out roughly LOC-neutral there, so it's left for a future pass rather than bundled into this story.🤖 Generated with Claude Code
Generated by Claude Code