Skip to content

test(query-core/hydration): replace 'vi.waitFor' with 'vi.advanceTimersByTimeAsync'#10428

Merged
sukvvon merged 2 commits intomainfrom
test/query-core-hydration-replace-waitFor-with-advanceTimersByTimeAsync
Apr 8, 2026
Merged

test(query-core/hydration): replace 'vi.waitFor' with 'vi.advanceTimersByTimeAsync'#10428
sukvvon merged 2 commits intomainfrom
test/query-core-hydration-replace-waitFor-with-advanceTimersByTimeAsync

Conversation

@sukvvon
Copy link
Copy Markdown
Collaborator

@sukvvon sukvvon commented Apr 8, 2026

🎯 Changes

  • Replace all vi.waitFor calls with vi.advanceTimersByTimeAsync in hydration.test.tsx
  • The file already uses vi.useFakeTimers() in beforeEach, so vi.waitFor polling was unnecessary
  • Test execution time reduced from ~1.79s to ~0.53s (~70% faster)

✅ 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

  • Tests
    • Updated test suite timer synchronization strategy for hydration/dehydration scenarios to improve test reliability and control flow handling.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c0403ee4-f898-4bc0-97ac-fd801c2b5066

📥 Commits

Reviewing files that changed from the base of the PR and between 2e26f14 and a9a9418.

📒 Files selected for processing (1)
  • packages/query-core/src/__tests__/hydration.test.tsx

📝 Walkthrough

Walkthrough

The hydration test suite's timer synchronization strategy was refactored to replace repeated polling-based vi.waitFor() blocks with direct promise capture and explicit vi.advanceTimersByTimeAsync() calls, consolidating multiple assertions into post-timer-advance checks.

Changes

Cohort / File(s) Summary
Hydration Test Suite
packages/query-core/src/__tests__/hydration.test.tsx
Refactored timer synchronization across multiple test scenarios: replaced vi.waitFor() polling with direct prefetchQuery() invocation, promise capture, and vi.advanceTimersByTimeAsync() calls; converted assertion patterns from polling-based waits to immediate checks post-timer-advance; one test signature updated to async.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Timers tick with cleaner grace,
No more waitFor's frantic race,
Promises caught, then freed at last,
Tests now sprint, no longer fast asleep!
Hydration flows with logic bright,
Async dreams made right.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: replacing vi.waitFor with vi.advanceTimersByTimeAsync in the hydration test file, which is the core focus of the changeset.
Description check ✅ Passed The description covers the main changes, rationale, test execution improvement, and properly indicates this is a dev-only change with checklist items appropriately marked.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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-replace-waitFor-with-advanceTimersByTimeAsync

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

@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Apr 8, 2026

View your CI Pipeline Execution ↗ for commit a22dffb

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 57s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-08 01:29:23 UTC

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

🚀 Changeset Version Preview

No changeset entries found. Merging this PR will not cause a version bump for any packages.

@sukvvon sukvvon self-assigned this Apr 8, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 8, 2026

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: a22dffb

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

size-limit report 📦

Path Size
react full 11.98 KB (0%)
react minimal 9.01 KB (0%)

@sukvvon sukvvon merged commit ef62f7b into main Apr 8, 2026
11 of 12 checks passed
@sukvvon sukvvon deleted the test/query-core-hydration-replace-waitFor-with-advanceTimersByTimeAsync branch April 8, 2026 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant