Repository navigation
test_runner: MockTimers does not support Temporal #63369
Description
Activity
- addedfeature requestIssues requesting new Node.js features.Issues requesting new Node.js features.test_runnerIssues and PRs related to the test runner subsystem.Issues and PRs related to the test runner subsystem.
on May 16, 2026 SGTM. It should be substantially more straightforward than the mock Date implementation, although you're right in that this would probably need to wait for internal access to the constructors.
mock.timers.tick(ms)andmock.timers.setTime(ms)should advance Temporal's view of "now" the same way they advanceDate.now(). The natural ergonomic is for'Date'and'Temporal'to be independently selectable but to share one underlying mock clock (so a test can mock both and have them agree).The only minor caveat for Temporal specifically is that the clock has no nanosecond precision, but that's no great drama – it wouldn't really make sense to change it, since its ultimate purpose is to drive millisecond-precision timers. It'd just need documenting.
Bikeshedding, but I'd probably add this as
'Temporal.Now', emphasising the fact that the rest of Temporal is unaffected.Reacted by Ethan ResnickReacted by sangwook- added 2 commits that reference this issue
on Aug 14, 2026 Since there has been no activity here for a while, I would like to pick this up if no one is currently working on it.
I have an implementation ready that follows the direction discussed above: a
'Temporal.Now'token formock.timers.enable({ apis })that mocksinstant(),zonedDateTimeISO(),plainDateTimeISO(),plainDateISO()andplainTimeISO()against the same internal clock asDate, withtimeZoneId()left untouched and the millisecond precision limitation documented. The mocked values are constructed through the internal utils from #63312, so I plan to open a PR once that lands. The branch already passes the full test suite on Linux (x64/arm64) and macOS on my fork.wafir645fcqs00 commented
on Aug 14, 2026 on Aug 14, 2026 via email · Hidden as spamshow commentMore actionswafir645fcqs0 commented
on Aug 14, 2026 on Aug 14, 2026 via email · Hidden as spamshow commentMore actions
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsAwaiting Triage
What is the problem this feature solves?
As of Node.js 26,
Temporalis enabled by default (#62526), and the platform is in the process of growing Temporal support across its APIs (#57891, #63154, #63312). One gap that doesn't seem to be tracked anywhere yet:node:test'sMockTimershas no way to controlTemporal.Now.MockTimers.enable({ apis })accepts'setTimeout' | 'setInterval' | 'setImmediate' | 'Date'. Passing'Temporal'(or any Temporal-related token) throwsERR_INVALID_ARG_VALUE. There is also no documented way to advance / freezeTemporal.Now.instant(),Temporal.Now.zonedDateTimeISO(), etc. via the mock clock.Concretely, this means any code that reads "now" via
Temporal.Nowinstead ofDate.now()can't be tested deterministically with the built-in test runner. With Temporal now being the recommended way to do date/time work, this is increasingly the common case — code migrating away fromDateloses its ability to useMockTimersfor time-based assertions.Repro
What is the feature you are proposing to solve the problem?
Extend
MockTimersso that, whenTemporalis in theapislist, the following are tied to the mock clock:Temporal.Now.instant()Temporal.Now.zonedDateTimeISO(timeZone?)Temporal.Now.plainDateTimeISO(timeZone?)Temporal.Now.plainDateISO(timeZone?)Temporal.Now.plainTimeISO(timeZone?)Temporal.Now.timeZoneId()(probably leave passthrough; only the clock should be virtual)mock.timers.tick(ms)andmock.timers.setTime(ms)should advance Temporal's view of "now" the same way they advanceDate.now(). The natural ergonomic is for'Date'and'Temporal'to be independently selectable but to share one underlying mock clock (so a test can mock both and have them agree).This likely depends on #63312 (internal Temporal utils) landing first, since
MockTimerswould need a way to constructTemporal.Instants from the mock epoch ms without round-tripping throughDate.What alternatives have you considered?
Temporal.Nowin a project-level abstraction that reads from a clock the tests can mock. Works but is viral — every consumer has to use the wrapper.Temporal.Nowin test setup. Brittle and doesn't compose withmock.timers.@sinonjs/fake-timershas the same gap upstream, so dropping the built-in runner doesn't help.Filing per discussion in #57891 (which explicitly scopes out test_runner/generic support) — happy to take this on if there's interest and #63312 looks close to landing.