query icon indicating copy to clipboard operation
query copied to clipboard

test(react-query-persist-client/PersistQueryClientProvider): replace 'await sleep' with 'sleep().then()' pattern in restoreClient and add additional timer advance for refetch verification

Open sukvvon opened this issue 4 weeks ago β€’ 5 comments

🎯 Changes

βœ… Checklist

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

πŸš€ Release Impact

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

Summary by CodeRabbit

  • Tests

    • Enhanced test coverage to verify that persisted data maintains stability across extended delays.
  • Bug Fixes

    • Refined error handling timing in the persist client to ensure errors are thrown consistently after a short delay, improving reliability of error scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.

sukvvon avatar Nov 23 '25 17:11 sukvvon

⚠️ No Changeset found

Latest commit: fb4071eaaff0fb0e478e69189b872873844b1d01

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Nov 23 '25 17:11 changeset-bot[bot]

Walkthrough

Test updates in PersistQueryClientProvider.test.tsx: query function implementations were rewritten to use async/await (previously used promise chains), and tests advance timers an additional 11ms to assert hydration state remains stable after the longer simulated delay.

Changes

Cohort / File(s) Summary
PersistQueryClientProvider Tests
packages/react-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx
Rewrote queryFn implementations from promise .then() chains to async/await with an await sleep(10) before producing values; added an extra 11ms timer advance in tests and updated assertions to verify hydration state remains stable after the extended delay.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Review the rewritten queryFn logic to ensure behavior matches prior promise-chain timing.
  • Verify the additional 11ms timer advance doesn't introduce flakiness in related timing-sensitive tests.

Possibly related PRs

  • TanStack/query#9859 β€” Modifies the same test file and adjusts async/delay handling patterns; likely related to timing/control-flow in tests.

Suggested reviewers

  • manudeli

Poem

πŸ‡ I waited ten, then yielded the prize,
Awaited the tick while timers ran wise.
Eleven more beats to prove what we knew β€”
Hydration held steady, the test passed true. πŸ₯•

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
βœ… Passed checks (2 passed)
Check name Status Explanation
Title check βœ… Passed The title accurately describes the main changes: converting callbacks to async/await and adding delayed assertions for test verification in PersistQueryClientProvider tests.
Description check βœ… Passed The description follows the template structure with completed checklist items and correctly identifies the change as dev-only with no release impact, though the 'Changes' section lacks detail.
✨ Finishing touches
  • [ ] πŸ“ Generate docstrings
πŸ§ͺ Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

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

coderabbitai[bot] avatar Nov 23 '25 17:11 coderabbitai[bot]

View your CI Pipeline Execution β†— for commit fb4071eaaff0fb0e478e69189b872873844b1d01

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... βœ… Succeeded 50s View β†—
nx run-many --target=build --exclude=examples/*... βœ… Succeeded 1s View β†—

☁️ Nx Cloud last updated this comment at 2025-12-19 01:56:11 UTC

nx-cloud[bot] avatar Nov 23 '25 17:11 nx-cloud[bot]

More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@9901
@tanstack/eslint-plugin-query

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

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@9901
@tanstack/query-broadcast-client-experimental

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

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

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

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@9901
@tanstack/query-sync-storage-persister

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

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

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

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

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

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

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

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

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

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

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

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

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

commit: fb4071e

pkg-pr-new[bot] avatar Nov 23 '25 17:11 pkg-pr-new[bot]

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 100.00%. Comparing base (f15b7fc) to head (fb4071e).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             main     #9901       +/-   ##
============================================
+ Coverage   45.89%   100.00%   +54.10%     
============================================
  Files         200         1      -199     
  Lines        8437        18     -8419     
  Branches     1943         2     -1941     
============================================
- Hits         3872        18     -3854     
+ Misses       4116         0     -4116     
+ Partials      449         0      -449     
Components Coverage Ξ”
@tanstack/angular-query-experimental βˆ… <ΓΈ> (βˆ…)
@tanstack/eslint-plugin-query βˆ… <ΓΈ> (βˆ…)
@tanstack/query-async-storage-persister βˆ… <ΓΈ> (βˆ…)
@tanstack/query-broadcast-client-experimental βˆ… <ΓΈ> (βˆ…)
@tanstack/query-codemods βˆ… <ΓΈ> (βˆ…)
@tanstack/query-core βˆ… <ΓΈ> (βˆ…)
@tanstack/query-devtools βˆ… <ΓΈ> (βˆ…)
@tanstack/query-persist-client-core βˆ… <ΓΈ> (βˆ…)
@tanstack/query-sync-storage-persister βˆ… <ΓΈ> (βˆ…)
@tanstack/query-test-utils βˆ… <ΓΈ> (βˆ…)
@tanstack/react-query βˆ… <ΓΈ> (βˆ…)
@tanstack/react-query-devtools βˆ… <ΓΈ> (βˆ…)
@tanstack/react-query-next-experimental βˆ… <ΓΈ> (βˆ…)
@tanstack/react-query-persist-client 100.00% <ΓΈ> (ΓΈ)
@tanstack/solid-query βˆ… <ΓΈ> (βˆ…)
@tanstack/solid-query-devtools βˆ… <ΓΈ> (βˆ…)
@tanstack/solid-query-persist-client βˆ… <ΓΈ> (βˆ…)
@tanstack/svelte-query βˆ… <ΓΈ> (βˆ…)
@tanstack/svelte-query-devtools βˆ… <ΓΈ> (βˆ…)
@tanstack/svelte-query-persist-client βˆ… <ΓΈ> (βˆ…)
@tanstack/vue-query βˆ… <ΓΈ> (βˆ…)
@tanstack/vue-query-devtools βˆ… <ΓΈ> (βˆ…)
:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Nov 23 '25 17:11 codecov[bot]