Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

feat(expect): log-scale expect pollers (#8010)

Pavel Feldman0a97e87817d1
diff --git a/src/test/matchers/toBeTruthy.ts b/src/test/matchers/toBeTruthy.ts
index a8b951ae26..1927ea67a1 100644
--- a/src/test/matchers/toBeTruthy.ts
+++ b/src/test/matchers/toBeTruthy.ts
@@ -48,7 +48,7 @@ export async function toBeTruthy<T>(
received = await query(remainingTime);
pass = !!received;
return pass === !matcherOptions.isNot;
- }, options.timeout, 100, testInfo._testFinished);
+ }, options.timeout, testInfo._testFinished);
const message = () => {
return matcherHint(matcherName, undefined, '', matcherOptions);
diff --git a/src/test/matchers/toEqual.ts b/src/test/matchers/toEqual.ts
index 02731e5614..0c337af63a 100644
--- a/src/test/matchers/toEqual.ts
+++ b/src/test/matchers/toEqual.ts
@@ -64,7 +64,7 @@ export async function toEqual<T>(
received = await query(remainingTime);
pass = equals(received, expected, [iterableEquality]);
return pass === !matcherOptions.isNot;
- }, options.timeout, 100, testInfo._testFinished);
+ }, options.timeout, testInfo._testFinished);
const message = pass
? () =>
diff --git a/src/test/matchers/toMatchText.ts b/src/test/matchers/toMatchText.ts
index f4acd68255..a060e5559a 100644
--- a/src/test/matchers/toMatchText.ts
+++ b/src/test/matchers/toMatchText.ts
@@ -80,7 +80,7 @@ export async function toMatchText(
pass = expected.test(received);
return pass === !matcherOptions.isNot;
- }, options.timeout, 100, testInfo._testFinished);
+ }, options.timeout, testInfo._testFinished);
const stringSubstring = options.matchSubstring ? 'substring' : 'string';
const message = pass
diff --git a/src/test/util.ts b/src/test/util.ts
index 4b83064cb6..a941065a46 100644
--- a/src/test/util.ts
+++ b/src/test/util.ts
@@ -71,7 +71,7 @@ export async function raceAgainstDeadline<T>(promise: Promise<T>, deadline: numb
return (new DeadlineRunner(promise, deadline)).result;
}
-export async function pollUntilDeadline(state: ReturnType<Expect['getState']>, func: (remainingTime: number) => Promise<boolean>, pollTime: number | undefined, pollInterval: number, deadlinePromise: Promise<void>): Promise<void> {
+export async function pollUntilDeadline(state: ReturnType<Expect['getState']>, func: (remainingTime: number) => Promise<boolean>, pollTime: number | undefined, deadlinePromise: Promise<void>): Promise<void> {
const playwrightActionTimeout = (state as any).playwrightActionTimeout;
pollTime = pollTime === 0 ? 0 : pollTime || playwrightActionTimeout;
const deadline = pollTime ? monotonicTime() + pollTime : 0;
@@ -82,6 +82,8 @@ export async function pollUntilDeadline(state: ReturnType<Expect['getState']>, f
return true;
});
+ const pollIntervals = [100, 250, 500];
+ let attempts = 0;
while (!aborted) {
const remainingTime = deadline ? deadline - monotonicTime() : 1000 * 3600 * 24;
if (remainingTime <= 0)
@@ -102,7 +104,7 @@ export async function pollUntilDeadline(state: ReturnType<Expect['getState']>, f
}
let timer: NodeJS.Timer;
- const timeoutPromise = new Promise(f => timer = setTimeout(f, pollInterval));
+ const timeoutPromise = new Promise(f => timer = setTimeout(f, pollIntervals[attempts++] || 1000));
await Promise.race([abortedPromise, timeoutPromise]);
clearTimeout(timer!);
}