Skip to content

Commit

Permalink
Support t.timeout(0) to restore default behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
novemberborn committed Jul 2, 2023
1 parent 6767126 commit 5bada71
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
2 changes: 2 additions & 0 deletions docs/02-execution-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ You cannot use `t.teardown()` in hooks either.
## `t.timeout(ms)`

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.

Use `t.timeout(0)` to restore the default behavior.
28 changes: 10 additions & 18 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ export default class Test {
this.pendingAttemptCount = 0;
this.planCount = null;
this.startedAt = 0;
this.timeoutMs = 0;
this.timeoutTimer = null;
}

Expand Down Expand Up @@ -418,28 +417,21 @@ export default class Test {
}

this.clearTimeout();
this.timeoutMs = ms;
this.timeoutTimer = nowAndTimers.setCappedTimeout(() => {
this.saveFirstError(new Error(message || 'Test timeout exceeded'));
if (ms !== 0) {
this.timeoutTimer = nowAndTimers.setCappedTimeout(() => {
this.saveFirstError(new Error(message || 'Test timeout exceeded'));

if (this.finishDueToTimeout) {
this.finishDueToTimeout();
}
}, ms);
if (this.finishDueToTimeout) {
this.finishDueToTimeout();
}
}, ms);
}

this.notifyTimeoutUpdate(this.timeoutMs);
this.notifyTimeoutUpdate(ms);
}

refreshTimeout() {
if (!this.timeoutTimer) {
return;
}

if (this.timeoutTimer.refresh) {
this.timeoutTimer.refresh();
} else {
this.timeout(this.timeoutMs);
}
this.timeoutTimer?.refresh();
}

clearTimeout() {
Expand Down

0 comments on commit 5bada71

Please sign in to comment.