test(query-devtools/utils): add tests for 'sortFns'#10650
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds a new comprehensive test suite for ChangesTest Suite for sortFns
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
View your CI Pipeline Execution ↗ for commit dae692c
☁️ Nx Cloud last updated this comment at |
🚀 Changeset Version PreviewNo changeset entries found. Merging this PR will not cause a version bump for any packages. |
size-limit report 📦
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/query-devtools/src/__tests__/utils.test.ts`:
- Around line 992-996: The test expectation and comparator disagree: update the
dateSort comparator (function dateSort in utils.tsx) to return 0 when
dataUpdatedAt timestamps are equal (instead of always -1), then update the test
in utils.test.ts (the case using buildQuery) to expect 0 for equal timestamps so
the comparator correctly signals equivalence; alternatively, if you intend
deterministic tie-breaking that places the second query first, keep dateSort
returning 1 on equal timestamps and change the test expectation to 1 — pick one
behavior and make dateSort and the test for buildQuery consistent.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 3c6d4ea5-bfbe-4abe-8081-dc6c56367e7b
📒 Files selected for processing (1)
packages/query-devtools/src/__tests__/utils.test.ts
dae692c to
77b31af
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/query-devtools/src/__tests__/utils.test.ts (1)
1032-1038: ⚡ Quick winHarden observer cleanup with
try/finallyin status tests.
unsubscribe()currently runs only on the success path. If an assertion fails, the subscription cleanup is skipped. Wrapping assertions intry/finallykeeps test isolation deterministic.Suggested patch
const unsubscribe = addObserver(idle) - - expect(statusSort(fetching, idle)).toBe(-1) - expect(statusSort(idle, fetching)).toBe(1) - - unsubscribe() + try { + expect(statusSort(fetching, idle)).toBe(-1) + expect(statusSort(idle, fetching)).toBe(1) + } finally { + unsubscribe() + } @@ const unsubscribe = addObserver(active) - - expect(statusSort(active, inactive)).toBe(-1) - expect(statusSort(inactive, active)).toBe(1) - - unsubscribe() + try { + expect(statusSort(active, inactive)).toBe(-1) + expect(statusSort(inactive, active)).toBe(1) + } finally { + unsubscribe() + }Also applies to: 1049-1055
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/query-devtools/src/__tests__/utils.test.ts` around lines 1032 - 1038, The test is not guaranteeing observer cleanup because unsubscribe() is only called on the success path; wrap the assertions that run while the observer is active in a try/finally so unsubscribe() always runs. Locate the test that calls addObserver(idle) and returns an unsubscribe function (reference symbols: addObserver, unsubscribe, statusSort, fetching, idle) and modify it so the assertions (expect(statusSort(...))) occur inside a try block and call unsubscribe() in the finally block; apply the same try/finally pattern to the analogous test around lines referencing the second occurrence (the block that spans the other status checks, e.g., the one noted at 1049-1055).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/query-devtools/src/__tests__/utils.test.ts`:
- Around line 1032-1038: The test is not guaranteeing observer cleanup because
unsubscribe() is only called on the success path; wrap the assertions that run
while the observer is active in a try/finally so unsubscribe() always runs.
Locate the test that calls addObserver(idle) and returns an unsubscribe function
(reference symbols: addObserver, unsubscribe, statusSort, fetching, idle) and
modify it so the assertions (expect(statusSort(...))) occur inside a try block
and call unsubscribe() in the finally block; apply the same try/finally pattern
to the analogous test around lines referencing the second occurrence (the block
that spans the other status checks, e.g., the one noted at 1049-1055).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 56bf6167-74c0-47c9-a201-fe01f1d094c1
📒 Files selected for processing (1)
packages/query-devtools/src/__tests__/utils.test.ts
77b31af to
a0aede9
Compare
🎯 Changes
Add unit tests for the
sortFnsrecord of query-sort helpers inquery-devtools/utils.tsx.sortFnsexposes three string keys ('last updated','query hash','status') that map to comparators used to order queries in the devtools panel.Cases:
'last updated'(dateSort) — places the more recently updated query first'query hash'(queryHashSort) — sorts queries alphabetically by query hash; returns 0 when hashes are identical'status'(statusAndDateSort) — places fetching queries before idle ones, places inactive (no observers) queries last, and falls back to "last updated" sort within the same status rankEach test uses a real
QueryClientandQueryinstance;'status'tests rely on a realQueryObserver(withenabled: falseto avoid triggering an automatic fetch). Subscribers are unsubscribed at the end of each test, andqueryClient.clear()runs inafterEachto keep tests isolated.dateSort's behavior whendataUpdatedAtvalues are equal is intentionally left unasserted while its intent is being clarified separately.✅ Checklist
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit
New Features
Tests