Skip to content

test: consolidate duplicated live-query test helpers#137

Merged
mbret merged 1 commit into
mainfrom
chore/consolidation-2026-07-19
Jul 19, 2026
Merged

test: consolidate duplicated live-query test helpers#137
mbret merged 1 commit into
mainfrom
chore/consolidation-2026-07-19

Conversation

@mbret

@mbret mbret commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Live-query test helpers

What was duplicated. src/lib/queries/useQuery$.reactivity.test.tsx and src/lib/queries/useQuery$.unmount.test.tsx each carried a byte-identical 38-line preamble before their describe block:

  • isDefined<T>() — narrowing guard
  • createQueryClient() — a QueryClient with gcTime: 0
  • liveQueryOptions — the { networkMode: "always", gcTime: 0, staleTime: Infinity } option block
  • createWrapper(queryClient) — the QueryClientProvider / QueryClientProvider$ wrapper

This 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 existing src/tests/utils.tsx), imported by both specs. The code is moved verbatim — same QueryClient config, same option values, same wrapper JSX — so behavior is unchanged. The now-unused @tanstack/react-query, react type, and QueryClientProvider$ imports were dropped from both specs (the repo compiles with noUnusedLocals).

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-query useQuery$ specs. Only these two files defined these helpers; the other query specs use genuinely different inline setups (plain new QueryClient(), PersistQueryClientProvider, custom client props), 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 in useMutation$, useSwitchMutation$, useConcatMutation$, createObservableQueryFn, and useObserve/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

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
@mbret
mbret merged commit 911d7be into main Jul 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants