From 934467d48485465f702ceeeeb6c31f6f46916175 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Tue, 6 Apr 2021 06:27:39 -0700 Subject: [PATCH 1/2] Give actionable error when pollFor times out --- test/api/TestUtils.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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; From 5973e8f0ddebfa0bf0610cfd9d8b7bee5a700f79 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Tue, 6 Apr 2021 06:28:49 -0700 Subject: [PATCH 2/2] Remove unused function --- test/api/TestUtils.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/test/api/TestUtils.ts b/test/api/TestUtils.ts index 20413565..2b1e8828 100644 --- a/test/api/TestUtils.ts +++ b/test/api/TestUtils.ts @@ -31,13 +31,6 @@ export async function pollFor(page: playwright.Page, evalOrFn: string | (() = } } -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;