Skip to content

Commit 5bada71

Browse files
committed
Support t.timeout(0) to restore default behavior
1 parent 6767126 commit 5bada71

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

docs/02-execution-context.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,5 @@ You cannot use `t.teardown()` in hooks either.
4545
## `t.timeout(ms)`
4646

4747
Set a timeout for the test, in milliseconds. The test will fail if this timeout is exceeded. The timeout is reset each time an assertion is made.
48+
49+
Use `t.timeout(0)` to restore the default behavior.

lib/test.js

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ export default class Test {
289289
this.pendingAttemptCount = 0;
290290
this.planCount = null;
291291
this.startedAt = 0;
292-
this.timeoutMs = 0;
293292
this.timeoutTimer = null;
294293
}
295294

@@ -418,28 +417,21 @@ export default class Test {
418417
}
419418

420419
this.clearTimeout();
421-
this.timeoutMs = ms;
422-
this.timeoutTimer = nowAndTimers.setCappedTimeout(() => {
423-
this.saveFirstError(new Error(message || 'Test timeout exceeded'));
420+
if (ms !== 0) {
421+
this.timeoutTimer = nowAndTimers.setCappedTimeout(() => {
422+
this.saveFirstError(new Error(message || 'Test timeout exceeded'));
424423

425-
if (this.finishDueToTimeout) {
426-
this.finishDueToTimeout();
427-
}
428-
}, ms);
424+
if (this.finishDueToTimeout) {
425+
this.finishDueToTimeout();
426+
}
427+
}, ms);
428+
}
429429

430-
this.notifyTimeoutUpdate(this.timeoutMs);
430+
this.notifyTimeoutUpdate(ms);
431431
}
432432

433433
refreshTimeout() {
434-
if (!this.timeoutTimer) {
435-
return;
436-
}
437-
438-
if (this.timeoutTimer.refresh) {
439-
this.timeoutTimer.refresh();
440-
} else {
441-
this.timeout(this.timeoutMs);
442-
}
434+
this.timeoutTimer?.refresh();
443435
}
444436

445437
clearTimeout() {

0 commit comments

Comments
 (0)