You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{beforeEach,describe,it,mock}from"node:test";importassertfrom"node:assert";describe("test",()=>{beforeEach(()=>{mock.timers.enable({apis: ["Date","setTimeout"]});});it("should test abort",{timeout: 5000},async()=>{consttimeout=AbortSignal.timeout(10000);constcatchSpy=mock.fn();constabortablePromise=newPromise((_,reject)=>{timeout.addEventListener("abort",()=>{reject(newError("promise rejected due to abort signal"));});}).catch(catchSpy);assert.equal(catchSpy.mock.calls.length,0);awaitPromise.resolve();mock.timers.tick(10000);awaitabortablePromise;assert.equal(catchSpy.mock.calls.length,1);});});
It times out.
How often does it reproduce? Is there a required condition?
Every time.
What is the expected behavior? Why is that the expected behavior?
The timer tick also ticks the timeout AbortSignal and triggers listeners if applicable, or the mock.timers.enable option supports a new "AbortSignal.timeout" API.
What do you see instead?
The test times out before the abort signal is triggered.
Additional information
In node versions <24, this results in a failing test after a few milliseconds with
"Promise resolution is still pending but the event loop has already resolved".
Hey, I can take this on. I’ll reproduce the issue locally, add a regression test, and work on a fix for the mock timers behavior. Could you please assign it to me so I can open a draft PR once I’ve got something working?
Activity
DeveloperViraj commentedon Oct 31, 2025
Hey, I can take this on. I’ll reproduce the issue locally, add a regression test, and work on a fix for the mock timers behavior. Could you please assign it to me so I can open a draft PR once I’ve got something working?
test_runner: add mock-timers support for AbortSignal.timeout
test_runner: add mock-timers support for AbortSignal.timeout
test_runner: add mock-timers support for AbortSignal.timeout