diff --git a/test/api/TestUtils.ts b/test/api/TestUtils.ts index f36d2830..20413565 100644 --- a/test/api/TestUtils.ts +++ b/test/api/TestUtils.ts @@ -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(page: playwright.Page, evalOrFn: string | (() => Promise), val: T, preFn?: () => Promise): Promise { +export async function pollFor(page: playwright.Page, evalOrFn: string | (() => Promise), val: T, preFn?: () => Promise, maxDuration?: number): Promise { if (preFn) { await preFn(); } @@ -18,12 +19,25 @@ export async function pollFor(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(r => { - setTimeout(() => r(pollFor(page, evalOrFn, val, preFn)), 1); + setTimeout(() => r(pollFor(page, evalOrFn, val, preFn, maxDuration! - 10)), 10); }); } } +function formatValue(value: any): string { + if (Array.isArray(value) || typeof value === 'object') { + return JSON.stringify(value); + } + return value + ''; +} + export async function writeSync(page: playwright.Page, data: string): Promise { await page.evaluate(` window.ready = false;