Merge branch 'master' into asserttimeout

This commit is contained in:
Daniel Imms
2021-04-06 07:07:58 -07:00
committed by GitHub
2 changed files with 10 additions and 3 deletions
+9 -2
View File
@@ -6,8 +6,9 @@
import * as playwright from 'playwright';
import deepEqual = require('deep-equal');
import { ITerminalOptions } from 'xterm';
import { deepStrictEqual, fail } from 'assert';
export async function pollFor<T>(page: playwright.Page, evalOrFn: string | (() => Promise<T>), val: T, preFn?: () => Promise<void>): Promise<void> {
export async function pollFor<T>(page: playwright.Page, evalOrFn: string | (() => Promise<T>), val: T, preFn?: () => Promise<void>, maxDuration?: number): Promise<void> {
if (preFn) {
await preFn();
}
@@ -18,8 +19,14 @@ export async function pollFor<T>(page: playwright.Page, evalOrFn: string | (() =
}
if (!deepEqual(result, val)) {
if (maxDuration === undefined) {
maxDuration = 2000;
}
if (maxDuration <= 0) {
deepStrictEqual(result, val, 'pollFor max duration exceeded');
}
return new Promise<void>(r => {
setTimeout(() => r(pollFor(page, evalOrFn, val, preFn)), 1);
setTimeout(() => r(pollFor(page, evalOrFn, val, preFn, maxDuration! - 10)), 10);
});
}
}