mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-15 06:02:57 +03:00
feat(expect): log-scale expect pollers (#8010)
This commit is contained in:
parent
7454647d8e
commit
0a97e87817
@ -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);
|
||||
|
@ -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
|
||||
? () =>
|
||||
|
@ -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
|
||||
|
@ -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!);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user