diff --git a/lib/api.js b/lib/api.js index dcab0fab9..eaf223650 100644 --- a/lib/api.js +++ b/lib/api.js @@ -16,6 +16,7 @@ import fork from './fork.js'; import * as globs from './globs.js'; import isCi from './is-ci.js'; import {getApplicableLineNumbers} from './line-numbers.js'; +import {setCappedTimeout} from './now-and-timers.cjs'; import {observeWorkerProcess} from './plugin-support/shared-workers.js'; import RunStatus from './run-status.js'; import scheduler from './scheduler.js'; @@ -52,7 +53,7 @@ class TimeoutTrigger { debounce() { if (this.timer === undefined) { - this.timer = setTimeout(() => this.trigger(), this.waitMs); + this.timer = setCappedTimeout(() => this.trigger(), this.waitMs); } else { this.timer.refresh(); } diff --git a/lib/now-and-timers.cjs b/lib/now-and-timers.cjs index 2576d7ef9..851bf6d4d 100644 --- a/lib/now-and-timers.cjs +++ b/lib/now-and-timers.cjs @@ -3,3 +3,14 @@ const timers = require('timers'); Object.assign(exports, timers); exports.now = Date.now; + +// Any delay larger than this value is ignored by Node.js, with a delay of `1` +// used instead. See . +const MAX_DELAY = (2 ** 31) - 1; + +function setCappedTimeout(callback, delay) { + const safeDelay = Math.min(delay, MAX_DELAY); + return timers.setTimeout(callback, safeDelay); +} + +exports.setCappedTimeout = setCappedTimeout; diff --git a/lib/test.js b/lib/test.js index d2bb93e2e..d6a39444a 100644 --- a/lib/test.js +++ b/lib/test.js @@ -405,7 +405,7 @@ export default class Test { this.clearTimeout(); this.timeoutMs = ms; - this.timeoutTimer = nowAndTimers.setTimeout(() => { + this.timeoutTimer = nowAndTimers.setCappedTimeout(() => { this.saveFirstError(new Error(message || 'Test timeout exceeded')); if (this.finishDueToTimeout) {