Skip to content

test(query-devtools/utils): add test for stale vs fresh rank in 'status' sort of 'sortFns'#10674

Merged
sukvvon merged 2 commits into
mainfrom
test/query-devtools-sort-fns-status-stale-vs-fresh
May 9, 2026
Merged

test(query-devtools/utils): add test for stale vs fresh rank in 'status' sort of 'sortFns'#10674
sukvvon merged 2 commits into
mainfrom
test/query-devtools-sort-fns-status-stale-vs-fresh

Conversation

@sukvvon
Copy link
Copy Markdown
Collaborator

@sukvvon sukvvon commented May 9, 2026

🎯 Changes

Add a test for the stale-vs-fresh rank distinction inside the 'status' sort of sortFns in query-devtools/utils.tsx. The existing 'status' cases compare across different getStatusRank levels (fetching/inactive/fall back), but never exercise the rank 1 (fresh) vs rank 2 (stale) split, leaving that branch unprotected.

The new test:

  • Builds a stale query (fetchStatus: 'idle' with a staleTime: 0 observer and dataUpdatedAt: 200).
  • Builds a fresh query (fetchStatus: 'idle' with an enabled: false observer and dataUpdatedAt: 100).
  • The stale one is intentionally given the more recent dataUpdatedAt, so a regression that collapses the stale/fresh ranks would fall back to dateSort and place the stale query first. Asserting that the fresh query is placed first proves the rank distinction is being respected.

✅ 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
    • Added test coverage for query sorting functionality, verifying correct ordering of stale and fresh queries in idle states.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 9, 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: a7304eae-eb14-4981-b8f1-f13c323c1e46

📥 Commits

Reviewing files that changed from the base of the PR and between a709b04 and a43032e.

📒 Files selected for processing (1)
  • packages/query-devtools/src/__tests__/utils.test.ts

📝 Walkthrough

Walkthrough

This PR adds a test case to sortFns['status'] verifying that stale queries are ordered after fresh queries when both are idle with observers. The test configures a stale query via staleTime: 0 and dataUpdatedAt, then asserts correct ordering against a fresh observed query with explicit subscription cleanup.

Changes

Query Status Sort Test Coverage

Layer / File(s) Summary
Status Sort Test Case
packages/query-devtools/src/__tests__/utils.test.ts
New test case asserts that statusSort correctly orders a stale idle query after a fresh idle query, both with observers, using explicit subscription setup and finally-based cleanup.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A test to order queries right,
Stale ones now know their proper sight,
When idle and observed, they fall behind,
Fresh queries first, that's what we find! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title clearly and accurately summarizes the main change: adding a test for stale vs fresh rank distinction in the 'status' sort function of sortFns.
Description check ✅ Passed The pull request description follows the template with all required sections completed, including detailed explanation of changes, a fully checked checklist, and clear release impact assessment.
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-devtools-sort-fns-status-stale-vs-fresh

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

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented May 9, 2026

View your CI Pipeline Execution ↗ for commit e415a00

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

☁️ Nx Cloud last updated this comment at 2026-05-09 07:36:59 UTC

@github-actions
Copy link
Copy Markdown
Contributor

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

pkg-pr-new Bot commented May 9, 2026

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/lit-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: a43032e

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 9, 2026

size-limit report 📦

Path Size
react full 12.1 KB (0%)
react minimal 9.07 KB (0%)

@sukvvon sukvvon merged commit a37c003 into main May 9, 2026
8 checks passed
@sukvvon sukvvon deleted the test/query-devtools-sort-fns-status-stale-vs-fresh branch May 9, 2026 07:38
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