mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Merge pull request #3294 from Tyriar/pollfor
Give actionable error when pollFor times out
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user