Skip to content

test(svelte-query): align 'advanceTimersByTimeAsync' with 'sleep' duration in wait-for-fire cases#10908

Merged
sukvvon merged 1 commit into
mainfrom
test/svelte-query-reduce-wait-for-fire-timers
Jun 9, 2026
Merged

test(svelte-query): align 'advanceTimersByTimeAsync' with 'sleep' duration in wait-for-fire cases#10908
sukvvon merged 1 commit into
mainfrom
test/svelte-query-reduce-wait-for-fire-timers

Conversation

@sukvvon

@sukvvon sukvvon commented Jun 9, 2026

Copy link
Copy Markdown
Member

🎯 Changes

Where a test advances fake timers solely to wait for a sleep(N) timer to fire and deliver data/state, align the vi.advanceTimersByTimeAsync(...) value with the corresponding sleep duration:

  • sleep(10)advanceTimersByTimeAsync(10) (was 11)
  • sleep(20)advanceTimersByTimeAsync(20) (was 21)
  • sleep(50)advanceTimersByTimeAsync(50) (was 51)
  • sleep(500)advanceTimersByTimeAsync(500) (was 501)

A setTimeout(fn, N) (which sleep uses) fires exactly at Nms, so advanceTimersByTimeAsync(N) is enough to flush it and the following microtasks; the extra +1 was unnecessary.

Threshold-crossing advances (e.g. staleTime boundaries that compare with strict >) are intentionally left as-is, since those genuinely need to advance past the boundary.

✅ 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
    • Adjusted fake-timer advancement values across multiple test suites to use more precise timing thresholds for assertions.

@coderabbitai

coderabbitai Bot commented Jun 9, 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: 006ba929-9e24-49fc-86b3-337eff93da52

📥 Commits

Reviewing files that changed from the base of the PR and between 2a4c2c9 and 5e23635.

📒 Files selected for processing (9)
  • packages/svelte-query/tests/HydrationBoundary/HydrationBoundary.svelte.test.ts
  • packages/svelte-query/tests/QueryClientProvider/QueryClientProvider.svelte.test.ts
  • packages/svelte-query/tests/createInfiniteQuery/createInfiniteQuery.svelte.test.ts
  • packages/svelte-query/tests/createQueries/createQueries.svelte.test.ts
  • packages/svelte-query/tests/createQuery/createQuery.svelte.test.ts
  • packages/svelte-query/tests/mutationOptions/mutationOptions.svelte.test.ts
  • packages/svelte-query/tests/useIsFetching/useIsFetching.svelte.test.ts
  • packages/svelte-query/tests/useIsMutating/useIsMutating.svelte.test.ts
  • packages/svelte-query/tests/useMutationState/useMutationState.svelte.test.ts

📝 Walkthrough

Walkthrough

This PR adjusts fake-timer advancements across nine svelte-query test files to use exact durations matching the mocked operation times, reducing overshoot from 1–2ms wait intervals to zero.

Changes

Test Fake-Timer Synchronization

Layer / File(s) Summary
Fake-timer progression alignment
packages/svelte-query/tests/HydrationBoundary/..., QueryClientProvider/..., createInfiniteQuery/..., createQueries/..., createQuery/..., mutationOptions/..., useIsFetching/..., useIsMutating/..., useMutationState/...
Reduces vi.advanceTimersByTimeAsync() values across all tests to match exact mocked durations: 10ms (was 11ms), 20ms (was 21ms), 50ms (was 51ms), 500ms (was 501ms). All test assertions, control flow, and expected outcomes remain unchanged; only timer precision is corrected.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • TanStack/query#10903: Adjusts fake-timer progression in createQuery.svelte.test.ts to update async query function resolution timing.
  • TanStack/query#10902: Rewrites the createQuery test suite with new reusable fixtures; overlaps with timer synchronization changes in the same file.

Suggested reviewers

  • TkDodo

Poem

🐰 A rabbit hops through test time zones,
Where timers tick in microseconds' tones,
From 11 to 10, a single leap,
Now mocks and waits are precision-deep!
The tests align, no more overshoot,
Just perfect timing, boot by boot!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: aligning advanceTimersByTimeAsync values with corresponding sleep durations in test wait-for-fire cases.
Description check ✅ Passed The description fully addresses the template requirements: changes are clearly explained with specific examples, the checklist is completed, and release impact is correctly marked as dev-only.
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.

✏️ 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/svelte-query-reduce-wait-for-fire-timers

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

@nx-cloud

nx-cloud Bot commented Jun 9, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 5e23635

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

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-06-09 00:41:30 UTC

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

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

@sukvvon sukvvon self-assigned this Jun 9, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jun 9, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/lit-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 5e23635

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

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

@sukvvon sukvvon merged commit 763782a into main Jun 9, 2026
9 checks passed
@sukvvon sukvvon deleted the test/svelte-query-reduce-wait-for-fire-timers branch June 9, 2026 00:43
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