Skip to content

fix(ext/node): support AbortSignal.timeout in node:test mock.timers#35474

Merged
littledivy merged 1 commit into
mainfrom
orch/divybot-586
Jun 25, 2026
Merged

fix(ext/node): support AbortSignal.timeout in node:test mock.timers#35474
littledivy merged 1 commit into
mainfrom
orch/divybot-586

Conversation

@divybot

@divybot divybot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary

node:test's mock.timers supports an AbortSignal.timeout API: when enabled, AbortSignal.timeout(delay) returns a signal that aborts based on the mocked virtual clock rather than real time. #33946 implemented mock.timers but intentionally shipped a subset of Node's supported APIs and left AbortSignal.timeout out, so mock.timers.enable({ apis: ['AbortSignal.timeout'] }) threw ERR_INVALID_ARG_VALUE.

This adds AbortSignal.timeout to the supported set:

  • It is added to SUPPORTED_APIS.
  • While enabled, globalThis.AbortSignal.timeout is 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 a TimeoutError once tick() / runAll() advance past delay.
  • Because the static method is not a globalThis binding, the original is saved/restored separately from the other mocked globals, and reset() (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_timers spec test with an AbortSignal.timeout case (31 → 32).

$ deno test tests/specs/node/node_test_mock_timers/test.js
ok | 32 passed | 0 failed

$ cargo test --test node_compat -- test-mock-timers-abortsignal-timeout
test node_compat::parallel::test-mock-timers-abortsignal-timeout.js ... ok

$ cargo test --test node_compat -- test-runner-mock-timers-with-timeout
test node_compat::parallel::test-runner-mock-timers-with-timeout.js ... ok

Towards #32987 / #35414.

Note: the remaining upstream mock-timers conformance files (-date.js, -scheduler.js, and the main test-runner-mock-timers.js) are intentionally left out. The first two rely on Node's automatic per-test mock restore (Deno's node:test has no per-test mock tracker yet) and scheduler.wait, and the main file requires --expose-internals / internal/timers. Those are separate follow-ups.

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
littledivy merged commit 5317e3c into main Jun 25, 2026
136 checks passed
@littledivy
littledivy deleted the orch/divybot-586 branch June 25, 2026 06:07
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.

2 participants