[Reporting] Optimize visualizations awaiter performance (#118012)
This commit is contained in:
parent
60a9221527
commit
5cccf0cdd6
|
@ -210,36 +210,16 @@ export class HeadlessChromiumDriver {
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async waitFor(
|
public async waitFor({
|
||||||
{
|
fn,
|
||||||
fn,
|
args,
|
||||||
args,
|
timeout,
|
||||||
toEqual,
|
}: {
|
||||||
timeout,
|
fn: EvaluateFn;
|
||||||
}: {
|
args: SerializableOrJSHandle[];
|
||||||
fn: EvaluateFn;
|
timeout: number;
|
||||||
args: SerializableOrJSHandle[];
|
}): Promise<void> {
|
||||||
toEqual: number;
|
await this.page.waitForFunction(fn, { timeout, polling: WAIT_FOR_DELAY_MS }, ...args);
|
||||||
timeout: number;
|
|
||||||
},
|
|
||||||
context: EvaluateMetaOpts,
|
|
||||||
logger: LevelLogger
|
|
||||||
): Promise<void> {
|
|
||||||
const startTime = Date.now();
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
const result = await this.evaluate({ fn, args }, context, logger);
|
|
||||||
if (result === toEqual) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Date.now() - startTime > timeout) {
|
|
||||||
throw new Error(
|
|
||||||
`Timed out waiting for the items selected to equal ${toEqual}. Found: ${result}. Context: ${context.context}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
await new Promise((r) => setTimeout(r, WAIT_FOR_DELAY_MS));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async setViewport(
|
public async setViewport(
|
||||||
|
|
|
@ -11,10 +11,23 @@ import { HeadlessChromiumDriver } from '../../browsers';
|
||||||
import { LayoutInstance } from '../layouts';
|
import { LayoutInstance } from '../layouts';
|
||||||
import { CONTEXT_WAITFORELEMENTSTOBEINDOM } from './constants';
|
import { CONTEXT_WAITFORELEMENTSTOBEINDOM } from './constants';
|
||||||
|
|
||||||
type SelectorArgs = Record<string, string>;
|
interface CompletedItemsCountParameters {
|
||||||
|
context: string;
|
||||||
|
count: number;
|
||||||
|
renderCompleteSelector: string;
|
||||||
|
}
|
||||||
|
|
||||||
const getCompletedItemsCount = ({ renderCompleteSelector }: SelectorArgs) => {
|
const getCompletedItemsCount = ({
|
||||||
return document.querySelectorAll(renderCompleteSelector).length;
|
context,
|
||||||
|
count,
|
||||||
|
renderCompleteSelector,
|
||||||
|
}: CompletedItemsCountParameters) => {
|
||||||
|
const { length } = document.querySelectorAll(renderCompleteSelector);
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.debug(`evaluate ${context}: waitng for ${count} elements, got ${length}.`);
|
||||||
|
|
||||||
|
return length >= count;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -40,11 +53,11 @@ export const waitForVisualizations = async (
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await browser.waitFor(
|
await browser.waitFor({
|
||||||
{ fn: getCompletedItemsCount, args: [{ renderCompleteSelector }], toEqual, timeout },
|
fn: getCompletedItemsCount,
|
||||||
{ context: CONTEXT_WAITFORELEMENTSTOBEINDOM },
|
args: [{ renderCompleteSelector, context: CONTEXT_WAITFORELEMENTSTOBEINDOM, count: toEqual }],
|
||||||
logger
|
timeout,
|
||||||
);
|
});
|
||||||
|
|
||||||
logger.debug(`found ${toEqual} rendered elements in the DOM`);
|
logger.debug(`found ${toEqual} rendered elements in the DOM`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
Loading…
Reference in a new issue