Skip to content

test(query-persist-client-core/persist): hoist 'queryClient' and 'persister' setup into 'beforeEach' and clear in 'afterEach'#10874

Merged
sukvvon merged 1 commit into
mainfrom
test/query-persist-client-core-persist-restore-setup
Jun 4, 2026
Merged

test(query-persist-client-core/persist): hoist 'queryClient' and 'persister' setup into 'beforeEach' and clear in 'afterEach'#10874
sukvvon merged 1 commit into
mainfrom
test/query-persist-client-core-persist-restore-setup

Conversation

@sukvvon
Copy link
Copy Markdown
Collaborator

@sukvvon sukvvon commented Jun 4, 2026

🎯 Changes

Hoists the repeated queryClient and persister instantiation in the persistQueryClientRestore test suite into a shared beforeEach, and clears the query client in afterEach, removing the duplicated setup from each test.

✅ 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
    • Refactored test suite to use shared setup and cleanup, improving organization and maintainability.
    • Clarified and localized simulated error scenarios within individual tests to improve isolation and readability.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 4, 2026

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: 09781276-9726-489f-aa16-a32971a030a3

📥 Commits

Reviewing files that changed from the base of the PR and between e877106 and 066d200.

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

📝 Walkthrough

Walkthrough

The persistQueryClientRestore test suite now uses a suite-level beforeEach to create shared queryClient and persister and an afterEach to clear queryClient; individual tests were refactored to use these shared fixtures and move error objects into test bodies.

Changes

Test setup consolidation in persistQueryClientRestore suite

Layer / File(s) Summary
beforeEach import and hook
packages/query-persist-client-core/src/__tests__/persist.test.ts
Add beforeEach to Vitest imports; introduce suite-level beforeEach to initialize queryClient and persister and afterEach to clear queryClient.
Refactor tests to use shared fixtures
packages/query-persist-client-core/src/__tests__/persist.test.ts
Move restoreError/removeError into test bodies; remove per-test queryClient/persister setup and stub persister.restoreClient/persister.removeClient against the shared instances across four tests.

Sequence Diagram(s)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • TanStack/query#10872: Refactors persist.test.ts to share queryClient/persister setup across the same persistQueryClientRestore test suite.

Poem

🐰
Hopping through tests with a cheerful tweak,
beforeEach plants seeds so we need not repeat,
errors tuck themselves into each tiny case,
shared fixtures sprint tests to a tidy place.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: hoisting queryClient and persister setup into beforeEach and clearing in afterEach, which matches the refactoring work shown in the summary.
Description check ✅ Passed The description includes all required template sections with appropriate content: a clear explanation of changes, completed checklist items, and proper release impact selection indicating this is 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/query-persist-client-core-persist-restore-setup

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

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Jun 4, 2026

View your CI Pipeline Execution ↗ for commit e877106

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

☁️ Nx Cloud last updated this comment at 2026-06-04 02:17:15 UTC

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 4, 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 Jun 4, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jun 4, 2026

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/lit-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 066d200

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 4, 2026

size-limit report 📦

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

…sister' setup into 'beforeEach' and clear in 'afterEach'
@sukvvon sukvvon force-pushed the test/query-persist-client-core-persist-restore-setup branch from e877106 to 066d200 Compare June 4, 2026 02:12
@sukvvon sukvvon changed the title test(query-persist-client-core/persist): hoist 'queryClient' and 'persister' setup into 'beforeEach' test(query-persist-client-core/persist): hoist 'queryClient' and 'persister' setup into 'beforeEach' and clear in 'afterEach' Jun 4, 2026
@sukvvon sukvvon merged commit a6fda44 into main Jun 4, 2026
9 checks passed
@sukvvon sukvvon deleted the test/query-persist-client-core-persist-restore-setup branch June 4, 2026 02:19
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