Skip to content
This repository was archived by the owner on Dec 11, 2025. It is now read-only.

test: useIntervalFn#75

Merged
Shinigami92 merged 1 commit intomainfrom
test-useIntervalFn-2
Jul 15, 2025
Merged

test: useIntervalFn#75
Shinigami92 merged 1 commit intomainfrom
test-useIntervalFn-2

Conversation

@Shinigami92
Copy link
Copy Markdown
Member

@Shinigami92 Shinigami92 commented Jul 14, 2025

this is theoretically a copy of #12, but only with tests that runs successfully

it aims to reduce the diff of #12 and I still hope that someone in the community can jump in and help us finding out why things are not working as expected
there is something fundamentally basic that stops this library of being used in production 🥲


Important

Add tests for useIntervalFn in Solid, Vue, and generic environments to cover pause/resume, immediate callback, and negative interval scenarios.

  • Tests Added:
    • index.solid.spec.ts: Tests useIntervalFn in Solid environment, covering pause in callback and negative interval scenarios.
    • index.spec.ts: Tests useIntervalFn in a generic environment, including basic pause/resume, pause in callback, and negative interval scenarios.
    • index.vue.spec.ts: Tests useIntervalFn in Vue environment, covering basic pause/resume, immediate callback, scope handling, and negative interval scenarios.

This description was created by Ellipsis for 8846459. You can customize this summary. It will automatically update as commits are pushed.

Summary by CodeRabbit

  • Tests
    • Added and expanded test coverage for the interval functionality across Solid, Vue, and core environments.
    • Introduced new tests for pause/resume behavior, immediate callback execution, dynamic interval changes, and handling of negative intervals.
    • Enhanced verification of active state and callback invocations, including edge cases and effect scope scenarios.

@Shinigami92 Shinigami92 self-assigned this Jul 14, 2025
@Shinigami92 Shinigami92 requested a review from JounQin as a code owner July 14, 2025 19:08
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Jul 14, 2025

⚠️ No Changeset found

Latest commit: 8846459

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

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jul 14, 2025

Walkthrough

New and expanded test suites were added for the useIntervalFn hook across Solid.js, Vue, and core environments. These tests cover pause/resume functionality, immediate callbacks, handling of negative intervals, and dynamic interval changes, using fake timers and reactive state assertions for thorough behavioral verification.

Changes

File(s) Change Summary
packages/unuse/src/useIntervalFn/index.solid.spec.ts Added new Solid.js test suite for useIntervalFn, covering pause/resume, immediate callback, and negative interval cases.
packages/unuse/src/useIntervalFn/index.spec.ts Expanded core test suite for useIntervalFn with comprehensive tests on pausing, resuming, dynamic intervals, and edge cases.
packages/unuse/src/useIntervalFn/index.vue.spec.ts Extended Vue test suite for useIntervalFn with new helper, tests for immediate callback, effect scope, and negative intervals.

Poem

In the warren of code, where intervals run,
Rabbits test pausing, resuming—such fun!
With timers and signals, they hop through each case,
Ensuring the callback keeps up with the pace.
From Vue to Solid, their coverage is prime—
Every interval’s now perfectly timed! 🐇⏱️


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 210b0bf and 8846459.

📒 Files selected for processing (3)
  • packages/unuse/src/useIntervalFn/index.solid.spec.ts (1 hunks)
  • packages/unuse/src/useIntervalFn/index.spec.ts (1 hunks)
  • packages/unuse/src/useIntervalFn/index.vue.spec.ts (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/unuse/src/useIntervalFn/index.solid.spec.ts (2)
packages/unuse/src/_testUtils/solid.ts (1)
  • describeSolid (11-26)
packages/unuse/src/useIntervalFn/index.ts (1)
  • useIntervalFn (52-112)
🪛 ESLint
packages/unuse/src/useIntervalFn/index.vue.spec.ts

[error] 5-5: Unable to resolve path to module 'vue'.

(import-x/no-unresolved)

packages/unuse/src/useIntervalFn/index.spec.ts

[error] 4-4: Unable to resolve path to module 'unuse-reactivity'.

(import-x/no-unresolved)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test
🔇 Additional comments (16)
packages/unuse/src/useIntervalFn/index.solid.spec.ts (3)

1-12: Test setup looks good.

The imports, test framework setup, and callback mock initialization are properly configured for Solid.js testing.


14-38: Test logic is correct and comprehensive.

The "pause in callback" test properly verifies:

  • Callback is invoked immediately with immediateCallback: true
  • Interval is paused when pause() is called from within the callback
  • isActive state transitions correctly
  • Callback count remains stable after pausing

The type assertion for isActive as Accessor<boolean> is appropriate for Solid.js.


40-46: Edge case testing is thorough.

The negative interval test correctly verifies that:

  • Interval doesn't start when interval value is negative
  • isActive remains false
  • Callback is never invoked

This aligns with the implementation logic that checks intervalValue <= 0.

packages/unuse/src/useIntervalFn/index.spec.ts (7)

1-1: Environment configuration is appropriate.

The happy-dom environment is suitable for testing DOM-related functionality in a Node.js environment.


14-19: Test setup is well-structured.

The callback mock setup and reset in beforeEach ensures clean test isolation.


21-40: Helper function provides excellent test coverage.

The exec function effectively tests the complete pause/resume lifecycle:

  • Verifies isActive is a reactive computed value
  • Tests initial active state and callback invocation
  • Validates pause behavior and state transition
  • Confirms resume functionality

The type assertion pattern is consistent and appropriate for the testing framework.


42-54: Comprehensive interval testing with reactive values.

This test excellently covers:

  • Static interval values
  • Reactive interval values using unSignal
  • Dynamic interval changes and their effects
  • Proper callback invocation timing

The test demonstrates both basic functionality and advanced reactive behavior.


56-84: Callback pausing logic is thoroughly tested.

The test correctly verifies the complex scenario where:

  • Callback pauses the interval from within itself
  • immediateCallback triggers the callback immediately
  • Subsequent resume calls behave correctly
  • State transitions are properly managed

This is a critical edge case that's well-covered.


86-92: Negative interval edge case is properly handled.

The test confirms that negative intervals are correctly rejected, with isActive remaining false and no callback invocations.


3-5: False positive: unuse-reactivity import is valid

The unuse-reactivity package is present under packages/unuse-reactivity and is successfully imported in numerous modules (including useIntervalFn, useWebSocket, toUnSignal, etc.). The static analysis warning is a false positive—no changes are needed.

Likely an incorrect or invalid review comment.

packages/unuse/src/useIntervalFn/index.vue.spec.ts (6)

5-5: Vue imports are appropriate for the test requirements.

The addition of effectScope and nextTick imports supports the new Vue-specific test cases. The static analysis error about unresolved Vue import is likely a false positive in a Vue project environment.


39-59: Helper function for immediate callback testing is well-designed.

The execImmediateCallback function effectively tests the scenario where callbacks are invoked immediately upon resume:

  • Verifies immediate callback invocation on start
  • Tests pause/resume behavior with immediate callback
  • Properly accounts for the additional callback invocation pattern

This complements the existing exec helper function nicely.


75-91: Immediate callback testing is comprehensive.

The test covers both static and reactive interval scenarios with immediate callback invocation. The use of nextTick() is appropriate for Vue's reactivity system to ensure state updates are processed.


93-102: Vue effect scope testing is excellent.

This test verifies that intervals are properly cleaned up when Vue effect scopes are stopped. This is crucial for Vue's reactivity system and prevents memory leaks:

  • Interval works correctly within the scope
  • Cleanup occurs when scope is stopped
  • No callbacks fire after scope disposal

This is a Vue-specific edge case that's well-covered.


104-128: Pause-in-callback behavior is consistently tested.

The test logic mirrors the implementation in other framework tests, ensuring consistent behavior across all environments. The Vue-specific type assertion using Ref<boolean> is appropriate.


130-136: Negative interval edge case is properly covered.

Consistent with other framework tests, this verifies that negative intervals are handled correctly in the Vue environment.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔴 Lines 81.59% (🎯 90%)
⬆️ +0.26%
1237 / 1516
🔴 Statements 81.59% (🎯 90%)
⬆️ +0.26%
1237 / 1516
🔴 Functions 77.88% (🎯 90%)
🟰 ±0%
81 / 104
🔴 Branches 84.34% (🎯 85%)
⬆️ +0.88%
334 / 396
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Unchanged Files
packages/unuse-angular/src/index.ts 94.2% 100% 83.33% 94.2% 143-146
packages/unuse-react/src/index.ts 69.86% 68.18% 100% 69.86% 49-55, 58-71, 139-143, 152
packages/unuse-reactivity/src/index.ts 0% 0% 0% 0% 1-5
packages/unuse-reactivity/src/unComputed/index.ts 88% 80% 100% 88% 74-75, 78-79, 84-85
packages/unuse-reactivity/src/unEffect/index.ts 95.65% 66.66% 100% 95.65% 26
packages/unuse-reactivity/src/unEffectScope/index.ts 90.9% 50% 100% 90.9% 24-25
packages/unuse-reactivity/src/unReactiveSystem/index.ts 84.76% 88% 66.66% 84.76% 38-44, 68-69, 80-81, 92-93, 96-97, 100-103, 154-155, 188-189
packages/unuse-reactivity/src/unSignal/index.ts 100% 100% 100% 100%
packages/unuse-reactivity/src/unWatch/index.ts 100% 100% 100% 100%
packages/unuse-solid/src/index.ts 83.09% 86.95% 100% 83.09% 52-59, 69, 141-145
packages/unuse-vue/src/index.ts 100% 100% 100% 100%
packages/unuse/src/index.ts 0% 0% 0% 0% 1-15
packages/unuse/src/_framework/index.ts 81.53% 62.5% 100% 81.53% 48-49, 67-68, 76-77, 85-86, 94-95, 102-103
packages/unuse/src/_testUtils/angular.ts 100% 100% 100% 100%
packages/unuse/src/_testUtils/react.ts 100% 100% 100% 100%
packages/unuse/src/_testUtils/solid.ts 100% 100% 100% 100%
packages/unuse/src/_testUtils/vue.ts 100% 100% 100% 100%
packages/unuse/src/isClient/index.ts 100% 0% 100% 100%
packages/unuse/src/isObject/index.ts 100% 100% 100% 100%
packages/unuse/src/isWorker/index.ts 66.66% 0% 100% 66.66% 5
packages/unuse/src/toArray/index.ts 100% 50% 100% 100%
packages/unuse/src/toUnSignal/index.ts 80.7% 84.21% 66.66% 80.7% 17-18, 31-32, 35-36, 43-44, 81-87, 98-99, 113-120, 130
packages/unuse/src/tryOnScopeDispose/index.ts 77.77% 80% 50% 77.77% 11-14, 23-24, 35-36, 40-41
packages/unuse/src/unAccess/index.ts 73% 80% 66.66% 73% 43-44, 48-49, 66-67, 71, 80-81, 84-93, 97-98, 104-105, 114-115, 118-119, 122-123
packages/unuse/src/unRefElement/index.ts 75% 33.33% 100% 75% 29, 36-37
packages/unuse/src/unResolve/index.ts 92.66% 97.22% 71.42% 92.66% 71-72, 93-94, 125-128
packages/unuse/src/useEventListener/index.ts 96.34% 86.66% 100% 96.34% 192-193, 198
packages/unuse/src/useIntervalFn/index.ts 100% 100% 100% 100%
packages/unuse/src/useToggle/index.ts 100% 100% 100% 100%
packages/unuse/src/useWebSocket/index.ts 46.66% 41.66% 33.33% 46.66% 161-163, 203-212, 216-218, 222-224, 233-235, 244-256, 262-263, 270-275, 278-308, 311-312, 315-326, 330-355, 367-368
Generated in workflow #203 for commit 8846459 by the Vitest Coverage Report Action

Copy link
Copy Markdown
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed everything up to 8846459 in 2 minutes and 5 seconds. Click for details.
  • Reviewed 262 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 8 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. packages/unuse/src/useIntervalFn/index.solid.spec.ts:25
  • Draft comment:
    Consider using a more explicit check for the type of 'isActive'. Right now, the test uses toSatisfy to verify it's a function (Solid accessor), but adding a comment or using a direct type-check (e.g. typeof pausable.isActive === 'function') may improve clarity.
  • Reason this comment was not posted:
    Confidence changes required: 50% <= threshold 50% None
2. packages/unuse/src/useIntervalFn/index.spec.ts:21
  • Draft comment:
    The helper function 'exec' encapsulates common pause/resume logic. Consider factoring similar helper patterns across different test files into a shared utility to reduce duplication and improve maintainability.
  • Reason this comment was not posted:
    Confidence changes required: 40% <= threshold 50% None
3. packages/unuse/src/useIntervalFn/index.spec.ts:86
  • Draft comment:
    The test name 'cant work when interval is negative' is informal. Consider renaming it to something clearer such as 'does not run when interval is negative' for better readability.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50% While the suggested name is slightly more formal and clearer, this is a relatively minor stylistic change. The existing name is still understandable and conveys the same meaning. The rules state we should not make purely informative comments or obvious suggestions. This seems more like a personal preference than a significant improvement. The current test name does use informal language ("cant" vs "cannot") and the suggested name is more professional. Poor test names can make code harder to maintain long-term. While better test names are good, this change is too minor to warrant a comment. The existing name is clear enough to understand the test's purpose. Delete this comment as it's a minor stylistic suggestion that doesn't significantly impact code quality or maintainability.
4. packages/unuse/src/useIntervalFn/index.vue.spec.ts:75
  • Draft comment:
    In the 'pause/resume with immediateCallback' test, nextTick() is used after updating the reactive interval. Ensure that this is sufficient for all reactivity updates; a brief comment explaining the choice could aid future readers.
  • Reason this comment was not posted:
    Confidence changes required: 30% <= threshold 50% None
5. General:8
  • Draft comment:
    All test files invoke vi.useFakeTimers at the top level without an accompanying teardown to restore real timers after tests. To avoid potential cross-test interference, consider adding an afterEach hook to reset timers (e.g., vi.useRealTimers or vi.clearAllTimers).
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
6. packages/unuse/src/useIntervalFn/index.solid.spec.ts:40
  • Draft comment:
    Typographical error: "cant" should be "can't" in the test description.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% While technically correct, this is an extremely minor stylistic issue that doesn't affect code functionality. Test descriptions are meant to be readable by developers, and both "cant" and "can't" are equally understandable. This feels like unnecessary nitpicking that doesn't improve code quality. Perhaps maintaining consistent and proper grammar throughout the codebase is important for professionalism and readability? While proper grammar is good, this level of nitpicking on test descriptions doesn't provide enough value to justify a code change and review cycle. Delete this comment as it's too minor and doesn't meaningfully improve code quality.
7. packages/unuse/src/useIntervalFn/index.spec.ts:86
  • Draft comment:
    Typo: The test description "cant work when interval is negative" should probably use an apostrophe (i.e., "can't work when interval is negative").
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% While technically correct, this is an extremely minor grammatical issue in a test description. Test descriptions are internal documentation and small grammatical issues don't impact code functionality or maintainability. The rules specifically say not to make comments that are obvious or unimportant. Perhaps proper grammar in test descriptions helps with code readability and professionalism? Maybe consistent style is important? While good grammar is nice to have, this is too minor of an issue to warrant a PR comment. It would create unnecessary noise in the review. Delete this comment as it's too minor and doesn't impact code quality or functionality.
8. packages/unuse/src/useIntervalFn/index.vue.spec.ts:130
  • Draft comment:
    Typographical error: The test description 'cant work when interval is negative' should probably use an apostrophe, e.g., "can't work when interval is negative", or be reworded for clarity.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% While technically correct that "cant" should be "can't", this is a very minor stylistic issue in a test description. Test descriptions are internal documentation and small grammatical issues don't impact code functionality or maintainability. The meaning is still perfectly clear without the apostrophe. Perhaps inconsistent grammar could make the codebase look less professional and impact readability slightly? The impact on readability is minimal, and this kind of minor stylistic feedback creates noise in PR reviews that distracts from more important issues. Delete this comment as it's too minor of an issue to warrant a PR comment. It violates the rule about not making obvious or unimportant comments.

Workflow ID: wflow_lzEd0TvpLJd8r1Mk

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@Shinigami92 Shinigami92 enabled auto-merge July 14, 2025 19:15
@Shinigami92 Shinigami92 added this pull request to the merge queue Jul 15, 2025
Merged via the queue into main with commit e4ba974 Jul 15, 2025
15 checks passed
@Shinigami92 Shinigami92 deleted the test-useIntervalFn-2 branch July 15, 2025 02:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants