Skip to content

Commit 95fcf2f

Browse files
authored
Merge pull request #3294 from Tyriar/pollfor
Give actionable error when pollFor times out
2 parents eedc314 + 5973e8f commit 95fcf2f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

test/api/TestUtils.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
import * as playwright from 'playwright';
77
import deepEqual = require('deep-equal');
88
import { ITerminalOptions } from 'xterm';
9+
import { deepStrictEqual, fail } from 'assert';
910

10-
export async function pollFor<T>(page: playwright.Page, evalOrFn: string | (() => Promise<T>), val: T, preFn?: () => Promise<void>): Promise<void> {
11+
export async function pollFor<T>(page: playwright.Page, evalOrFn: string | (() => Promise<T>), val: T, preFn?: () => Promise<void>, maxDuration?: number): Promise<void> {
1112
if (preFn) {
1213
await preFn();
1314
}
@@ -18,8 +19,14 @@ export async function pollFor<T>(page: playwright.Page, evalOrFn: string | (() =
1819
}
1920

2021
if (!deepEqual(result, val)) {
22+
if (maxDuration === undefined) {
23+
maxDuration = 2000;
24+
}
25+
if (maxDuration <= 0) {
26+
deepStrictEqual(result, val, 'pollFor max duration exceeded');
27+
}
2128
return new Promise<void>(r => {
22-
setTimeout(() => r(pollFor(page, evalOrFn, val, preFn)), 1);
29+
setTimeout(() => r(pollFor(page, evalOrFn, val, preFn, maxDuration! - 10)), 10);
2330
});
2431
}
2532
}

0 commit comments

Comments
 (0)