Skip to content

test(query-core/hydration): replace 'vi.waitFor' with 'vi.advanceTimersByTimeAsync' and use 'queryKey' helper for infinite query tests#10944

Merged
sukvvon merged 3 commits into
mainfrom
test/query-core-hydration-advance-timers
Jun 27, 2026
Merged

test(query-core/hydration): replace 'vi.waitFor' with 'vi.advanceTimersByTimeAsync' and use 'queryKey' helper for infinite query tests#10944
sukvvon merged 3 commits into
mainfrom
test/query-core-hydration-advance-timers

Conversation

@sukvvon

@sukvvon sukvvon commented Jun 14, 2026

Copy link
Copy Markdown
Member

🎯 Changes

The infinite query tests in hydration.test.tsx wrapped prefetchInfiniteQuery/fetchInfiniteQuery calls in vi.waitFor(...) while the suite runs under fake timers (vi.useFakeTimers()). vi.waitFor polls a callback that returns a fresh prefetch promise on every tick, which is the wrong tool under fake timers and made these tests slow.

This replaces that pattern with the standard fake-timer flow already used throughout the file.

Changes:

  • Replace 9 vi.waitFor(() => client.prefetch/fetchInfiniteQuery(...)) calls with const promise = client.prefetch/fetchInfiniteQuery(...) + await vi.advanceTimersByTimeAsync(...) + await promise.
  • Use sleep(10) in the converted queryFns and advance by 10 (single page) / 20 (the pages: 2 test) so the timer control is deterministic.
  • Drop the redundant async from the converted queryFn: ({ pageParam }) => sleep(...).then(...) arrows (they only return a promise).
  • Replace hard-coded string query keys with the queryKey() helper in these tests for uniqueness and consistency with the rest of the file.

No assertions were changed. The whole hydration.test.tsx suite (42 tests) passes with no type errors, and the run is noticeably faster after removing the vi.waitFor polling.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

Release Notes

  • Tests
    • Enhanced coverage for infinite query hydration/dehydration, including preservation of infinite-query behavior and query typing across new caches.
    • Verified page and page-parameter structure remains correct after hydration and during refetch, including multi-page infinite queries.
    • Improved test timing by using direct promise awaiting and controlled timer advancement instead of wait-for patterns.

…rsByTimeAsync' and use 'queryKey' helper for infinite query tests
@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7251485b-a8a1-4f13-9bc8-bc760f69fffe

📥 Commits

Reviewing files that changed from the base of the PR and between f398a4d and a5b6226.

📒 Files selected for processing (1)
  • packages/query-core/src/__tests__/hydration.test.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/query-core/src/tests/hydration.test.tsx

📝 Walkthrough

Walkthrough

The hydration test suite for infinite queries is refactored: tests now use prefetchInfiniteQuery plus fake-timer advancement, dynamically generated query keys, and updated assertions for queryType, pages, and pageParams across hydration, refetch, setOptions, and multi-page cases.

Changes

Infinite query hydration test updates

Layer / File(s) Summary
Basic hydration and infiniteQueryBehavior attachment tests
packages/query-core/src/__tests__/hydration.test.tsx
Rewrites the first two tests to prefetch with fake timers, dehydrate, assert queryType: 'infinite' survives hydration, then call fetchInfiniteQuery and check the resulting pages/pageParams shape.
Dehydrate/hydrate cycle type restoration and refetch setup
packages/query-core/src/__tests__/hydration.test.tsx
Updates the restore-type test to match the dehydrated query by generated key and assert queryType: 'infinite' before and after hydration, then prepares the refetch-after-hydration case with prefetchInfiniteQuery and timer advancement.
Refetch-after-hydration assertions
packages/query-core/src/__tests__/hydration.test.tsx
Reads the hydrated cache before refetch, then runs fetchInfiniteQuery with timer advancement and asserts the returned pages and pageParams structure after refetch.
setOptions type persistence and multi-page hydration tests
packages/query-core/src/__tests__/hydration.test.tsx
Rewrites the setOptions test to confirm the query stays 'infinite' after setOptions; refactors the multi-page case to prefetch two pages, hydrate them, and verify both pages and pageParams persist through refetch.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Hop, hop, hydrate, the cache stays bright,
Infinite pages preserved just right.
Keys now dance and timers sprint,
queryType: 'infinite' leaves its print.
Refetch the burrow, pages still align,
In rabbit-cache gardens, all looks fine.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main test-only change: replacing vi.waitFor with fake-timer advancement and queryKey helpers.
Description check ✅ Passed The description matches the required template and includes changes, checklist, and release-impact sections with sufficient detail.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/query-core-hydration-advance-timers

Comment @coderabbitai help to get the list of available commands.

@sukvvon sukvvon self-assigned this Jun 14, 2026
@nx-cloud

nx-cloud Bot commented Jun 14, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit a5b6226

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 7m 13s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1m 52s View ↗

☁️ Nx Cloud last updated this comment at 2026-06-27 19:59:13 UTC

@github-actions

github-actions Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

1 package(s) bumped directly, 24 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/query-devtools 5.101.1 → 5.101.2 Changeset
@tanstack/angular-query-experimental 5.101.1 → 5.101.2 Dependent
@tanstack/angular-query-persist-client 5.101.1 → 5.101.2 Dependent
@tanstack/eslint-plugin-query 5.101.1 → 5.101.2 Dependent
@tanstack/lit-query 0.2.8 → 0.2.9 Dependent
@tanstack/preact-query 5.101.1 → 5.101.2 Dependent
@tanstack/preact-query-devtools 5.101.1 → 5.101.2 Dependent
@tanstack/preact-query-persist-client 5.101.1 → 5.101.2 Dependent
@tanstack/query-async-storage-persister 5.101.1 → 5.101.2 Dependent
@tanstack/query-broadcast-client-experimental 5.101.1 → 5.101.2 Dependent
@tanstack/query-core 5.101.1 → 5.101.2 Dependent
@tanstack/query-persist-client-core 5.101.1 → 5.101.2 Dependent
@tanstack/query-sync-storage-persister 5.101.1 → 5.101.2 Dependent
@tanstack/react-query 5.101.1 → 5.101.2 Dependent
@tanstack/react-query-devtools 5.101.1 → 5.101.2 Dependent
@tanstack/react-query-next-experimental 5.101.1 → 5.101.2 Dependent
@tanstack/react-query-persist-client 5.101.1 → 5.101.2 Dependent
@tanstack/solid-query 5.101.1 → 5.101.2 Dependent
@tanstack/solid-query-devtools 5.101.1 → 5.101.2 Dependent
@tanstack/solid-query-persist-client 5.101.1 → 5.101.2 Dependent
@tanstack/svelte-query 6.1.35 → 6.1.36 Dependent
@tanstack/svelte-query-devtools 6.1.35 → 6.1.36 Dependent
@tanstack/svelte-query-persist-client 6.1.35 → 6.1.36 Dependent
@tanstack/vue-query 5.101.1 → 5.101.2 Dependent
@tanstack/vue-query-devtools 6.1.35 → 6.1.36 Dependent

@pkg-pr-new

pkg-pr-new Bot commented Jun 14, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@10944

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@10944

@tanstack/lit-query

npm i https://pkg.pr.new/@tanstack/lit-query@10944

@tanstack/preact-query

npm i https://pkg.pr.new/@tanstack/preact-query@10944

@tanstack/preact-query-devtools

npm i https://pkg.pr.new/@tanstack/preact-query-devtools@10944

@tanstack/preact-query-persist-client

npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@10944

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@10944

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@10944

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@10944

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@10944

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@10944

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@10944

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@10944

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@10944

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@10944

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@10944

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@10944

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@10944

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@10944

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@10944

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@10944

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@10944

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@10944

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@10944

commit: a5b6226

@github-actions

github-actions Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
react full 12.13 KB (0%)
react minimal 9.08 KB (0%)

@sukvvon sukvvon merged commit a4587b6 into main Jun 27, 2026
9 checks passed
@sukvvon sukvvon deleted the test/query-core-hydration-advance-timers branch June 27, 2026 20:03
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.

1 participant