Skip to content

Conversation

@miinhho
Copy link
Contributor

@miinhho miinhho commented Aug 23, 2025

Summary

Replaced real timer usage with fake timers in debounce and throttle tests to eliminate flaky test risks and significantly improve test execution time.

Problem

  • Tests were using real timers with delay() function, making them slow and potentially flaky
  • Real timer-based tests are susceptible to timing issues in CI environments
  • Total test execution time was unnecessarily long due to actual time delays

Solution

  • Targeted approach: Only replaced real timers with fake timers for debounce and throttle tests that were the primary cause of slow test execution
  • Simple replacements: For straightforward cases, replaced delay() calls with vi.advanceTimersByTime() for precise time control
  • Preserved complex tests: When tests required additional modifications beyond simple delay() replacement, maintained original tests using vi.useRealTimers() to avoid breaking existing functionality

Performance Improvements

Individual Test Files

Test File Before After Improvement
src/compat/function/debounce.spec.ts 4.08s 1.16s 3.52x faster
src/compat/function/throttle.spec.ts 5.08s 2.02s 2.52x faster
src/function/debounce.spec.ts 903ms 12ms 75.25x faster
src/function/throttle.spec.ts 1.45s 15ms 96.67x faster

Overall Test Suite Impact

Test execution time: 19.64s → 11.33s (42.3% improvement)

Benefits

  • Eliminated flaky test risks - No dependency on system timing
  • Faster CI/CD pipeline - Reduced test execution time by 42%
  • More reliable tests - Deterministic timing behavior

- After migating to fake timer, test time reduced from 4.08s to 1.16s
- Test logic is not changed
- After migating to fake timer, test time reduced from 5.08s to 2.02s
- Test logic is not changed
- After migating to fake timer, test time reduced from 903ms to 12ms
- Test logic is not changed
- After migating to fake timer, test time reduced from 1450ms to 15ms
- Test logic is not changed
Copilot AI review requested due to automatic review settings August 23, 2025 15:56
@vercel
Copy link

vercel bot commented Aug 23, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
es-toolkit Ready Ready Preview Comment Nov 18, 2025 0:58am

@codecov-commenter
Copy link

codecov-commenter commented Aug 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.97%. Comparing base (8beb7a3) to head (486cb92).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1359   +/-   ##
=======================================
  Coverage   99.97%   99.97%           
=======================================
  Files         468      468           
  Lines        4459     4459           
  Branches     1313     1313           
=======================================
  Hits         4458     4458           
  Misses          1        1           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@miinhho miinhho requested a review from Copilot August 24, 2025 02:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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.

3 participants