Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
}
Expand Down
11 changes: 11 additions & 0 deletions lib/now-and-timers.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://nodejs.org/api/timers.html#settimeoutcallback-delay-args>.
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;
2 changes: 1 addition & 1 deletion lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down