Update to sinon/fake-timers v15 and add setTickMode to timer controls #8726
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This change exposes the
setTickModefunction from the underlyingfake-timerslibrary.This is to align with the new feature introduced in
fake-timers.The new
setTickModemethod allows developers to configure whether time should auto advance and what the delta should be after the clock has been created. Prior to this, it could only be done at creation time withshouldAdvanceTime: true.This also adds a new mode for automatically advancing time that moves more quickly than the existing shouldAdvanceTime, which uses real time.
Testing with mock clocks can often turn into a real struggle when dealing with situations where some work in the test is truly async and other work is captured by the mock clock. When using mock clocks, testers are always forced to write tests with intimate knowledge of when the mock clock needs to be ticked. It is ideal for test code to be written in a way that is independent of whether a mock clock is installed.
shouldAdvanceTimeis essentiallysetInterval(() => clock.tick(ms), ms)while this feature isconst loop = () => setTimeout(() => clock.nextAsync().then(() => loop()), 0);There are two key differences:
shouldAdvanceTimeusesclock.tick(ms)so it synchronously runs all timers inside the "ms" of the clock queue. This doesn't allow the microtask queue to empty between the macrotask timers in the clock.shouldAdvanceTimeuses real time to advance the same amount of real time in the mock clock.setTickMode({mode: "nextAsync"})advances time as quickly possible and as far as necessary.See: sinonjs/fake-timers@108efae
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yamlunless you introduce a new test example.Tests
pnpm test:ci.Documentation
pnpm run docscommand.Changesets
feat:,fix:,perf:,docs:, orchore:.