Skip to content

test(svelte-query/createQueries): move test files into 'createQueries' directory#10386

Merged
sukvvon merged 2 commits intomainfrom
test/svelte-query-createQueries-move-tests
Apr 5, 2026
Merged

test(svelte-query/createQueries): move test files into 'createQueries' directory#10386
sukvvon merged 2 commits intomainfrom
test/svelte-query-createQueries-move-tests

Conversation

@sukvvon
Copy link
Copy Markdown
Collaborator

@sukvvon sukvvon commented Apr 5, 2026

🎯 Changes

✅ 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

Release Notes

  • Tests
    • Reorganized and expanded test coverage for query functionality with improved validation of runtime behavior, data transitions, and type safety across different usage patterns.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 5, 2026

📝 Walkthrough

Walkthrough

The createQueries test suite was reorganized into a nested directory structure with a shared QueryClient instance replacing per-test fake timers. Test coverage was expanded with runtime behavior validation and comprehensive compile-time type assertions. The type-definition test import path was updated to reflect the new directory layout.

Changes

Cohort / File(s) Summary
Test Suite Reorganization
packages/svelte-query/tests/createQueries.svelte.test.ts (removed), packages/svelte-query/tests/createQueries/createQueries.svelte.test.ts (added)
Migrated test suite to nested directory structure. Replaced suite-level fake timers with a shared QueryClient instance created once per suite and cleared per-test. Added runtime behavior tests validating query state transitions, refetch tracking, and query combination via combine. Expanded TypeScript type-level assertions covering generic parameter inference, select field enforcement, and callback argument types. Refactored restoring-period test to manage timers locally.
Type Definition Test Path Update
packages/svelte-query/tests/createQueries/createQueries.test-d.ts
Updated import paths from ../src/index.js to ../../src/index.js to align with new nested directory structure.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Tests were scattered, now they're neat,
In folders tidy, organized sweet,
No more timers, just clean state,
Types assert—a rabbit's fate!
Hopping through the query's nest,

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main structural change: moving test files into a subdirectory and organizing related test components together.
Description check ✅ Passed The description covers the key changes, follows the template structure, and provides context about consolidation with existing test components. Checklist items are appropriately marked.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ 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-createQueries-move-tests

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

@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Apr 5, 2026

View your CI Pipeline Execution ↗ for commit de2ad93

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

☁️ Nx Cloud last updated this comment at 2026-04-05 06:47:43 UTC

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 5, 2026

🚀 Changeset Version Preview

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

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 5, 2026

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: de2ad93

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 5, 2026

size-limit report 📦

Path Size
react full 11.98 KB (0%)
react minimal 9.01 KB (0%)

@sukvvon sukvvon self-assigned this Apr 5, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/svelte-query/tests/createQueries/createQueries.svelte.test.ts`:
- Around line 19-20: The shared teardown afterEach currently only calls
queryClient.clear(), so when tests switch to fake timers (e.g. the test at line
939) a failing test can leave Vitest in fake-timer mode; update the afterEach
block to also call vi.useRealTimers() to ensure timers are reset on every
teardown — modify the afterEach that references queryClient.clear() to invoke
vi.useRealTimers() alongside clearing the query client.
- Around line 23-25: The test helper withEffectRoot in
packages/svelte-query/tests/utils.svelte.ts currently calls cleanup() only after
await promise succeeds; change it so cleanup() runs regardless of promise
resolution by wrapping the awaited call in a try/finally (or use
promise.finally) that always calls cleanup(), ensuring the effect root is
unsubscribed even when the wrapped async function throws or rejects; target the
withEffectRoot wrapper and the existing cleanup() call to implement this
unconditional cleanup.
🪄 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: 398c3a20-9817-449f-8c28-7ef99ff5f129

📥 Commits

Reviewing files that changed from the base of the PR and between 5f5cfab and 2e88021.

📒 Files selected for processing (3)
  • packages/svelte-query/tests/createQueries.svelte.test.ts
  • packages/svelte-query/tests/createQueries/createQueries.svelte.test.ts
  • packages/svelte-query/tests/createQueries/createQueries.test-d.ts
💤 Files with no reviewable changes (1)
  • packages/svelte-query/tests/createQueries.svelte.test.ts

Comment on lines 19 to +20
afterEach(() => {
vi.useRealTimers()
queryClient.clear()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Reset Vitest timers in the shared teardown.

Line 939 switches this suite to fake timers, but the reset currently happens only at the tail of that one test. If any earlier assertion throws, later cases inherit fake timers and fail for unrelated reasons. Add vi.useRealTimers() to afterEach so cleanup is failure-safe.

🧹 Proposed fix
  afterEach(() => {
    queryClient.clear()
+   vi.useRealTimers()
  })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
afterEach(() => {
vi.useRealTimers()
queryClient.clear()
afterEach(() => {
queryClient.clear()
vi.useRealTimers()
})
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/svelte-query/tests/createQueries/createQueries.svelte.test.ts`
around lines 19 - 20, The shared teardown afterEach currently only calls
queryClient.clear(), so when tests switch to fake timers (e.g. the test at line
939) a failing test can leave Vitest in fake-timer mode; update the afterEach
block to also call vi.useRealTimers() to ensure timers are reset on every
teardown — modify the afterEach that references queryClient.clear() to invoke
vi.useRealTimers() alongside clearing the query client.

Comment on lines +23 to +25
it(
'should return the correct states',
withEffectRoot(async () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

withEffectRoot needs failure-safe cleanup before broad reuse.

packages/svelte-query/tests/utils.svelte.ts:24-32 only calls cleanup() after await promise succeeds. Any rejected promise or failed expectation in these new withEffectRoot(...) cases skips cleanup and leaves the effect root subscribed for later tests.

🔧 Proposed fix in packages/svelte-query/tests/utils.svelte.ts
 export function withEffectRoot(fn: () => void | Promise<void>) {
   return async () => {
     let promise: void | Promise<void> = Promise.resolve()
     const cleanup = $effect.root(() => {
       promise = fn()
     })
-    await promise
-    cleanup()
+    try {
+      await promise
+    } finally {
+      cleanup()
+    }
   }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it(
'should return the correct states',
withEffectRoot(async () => {
export function withEffectRoot(fn: () => void | Promise<void>) {
return async () => {
let promise: void | Promise<void> = Promise.resolve()
const cleanup = $effect.root(() => {
promise = fn()
})
try {
await promise
} finally {
cleanup()
}
}
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/svelte-query/tests/createQueries/createQueries.svelte.test.ts`
around lines 23 - 25, The test helper withEffectRoot in
packages/svelte-query/tests/utils.svelte.ts currently calls cleanup() only after
await promise succeeds; change it so cleanup() runs regardless of promise
resolution by wrapping the awaited call in a try/finally (or use
promise.finally) that always calls cleanup(), ensuring the effect root is
unsubscribed even when the wrapped async function throws or rejects; target the
withEffectRoot wrapper and the existing cleanup() call to implement this
unconditional cleanup.

@sukvvon sukvvon merged commit 422a997 into main Apr 5, 2026
8 checks passed
@sukvvon sukvvon deleted the test/svelte-query-createQueries-move-tests branch April 5, 2026 06:50
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