fix(ext/node): support AbortSignal.timeout in node:test mock.timers#35474
Merged
Conversation
Node's test.mock.timers supports an AbortSignal.timeout API that returns a signal aborting on the virtual clock; PR #33946 implemented mock.timers but left this API out of the supported set, so enabling it threw ERR_INVALID_ARG_VALUE. Add AbortSignal.timeout to the supported APIs. When enabled, the mocked static method schedules a virtual timer that aborts the returned signal with a TimeoutError as tick()/runAll() advance the clock, and reset() restores the original static method. This enables the upstream Node conformance tests parallel/test-mock-timers-abortsignal-timeout.js and parallel/test-runner-mock-timers-with-timeout.js, and extends the node_test_mock_timers spec test. Towards #32987 / #35414
littledivy
approved these changes
Jun 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
node:test'smock.timerssupports anAbortSignal.timeoutAPI: when enabled,AbortSignal.timeout(delay)returns a signal that aborts based on the mocked virtual clock rather than real time. #33946 implementedmock.timersbut intentionally shipped a subset of Node's supported APIs and leftAbortSignal.timeoutout, somock.timers.enable({ apis: ['AbortSignal.timeout'] })threwERR_INVALID_ARG_VALUE.This adds
AbortSignal.timeoutto the supported set:SUPPORTED_APIS.globalThis.AbortSignal.timeoutis replaced with a function that schedules a virtual timer (via the same internal clock as the other mocked timers) and aborts the returned signal with aTimeoutErroroncetick()/runAll()advance pastdelay.globalThisbinding, the original is saved/restored separately from the other mocked globals, andreset()(and[Symbol.dispose]) put it back.Tests
Enables two upstream Node conformance tests that now pass:
parallel/test-mock-timers-abortsignal-timeout.js(passes with this change)parallel/test-runner-mock-timers-with-timeout.js(already passing; was simply not enabled)and extends the
node_test_mock_timersspec test with anAbortSignal.timeoutcase (31 → 32).Towards #32987 / #35414.