Skip to content

Commit b17d3db

Browse files
VIA-227 JS Implement LCP rather than full page load as benchmark timing
1 parent af4087d commit b17d3db

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

e2e/e2e-helpers.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,25 @@ export const clickLinkAndExpectPageTitle = async (page: Page, linkText: string,
55
await expect(page).toHaveTitle(expectedPageTitle);
66
}
77

8+
export const determineLargestContentfulPaint = async () => {
9+
10+
}
11+
12+
const lcpTime = async (): Promise<number> => {
13+
return new Promise((resolve) => {
14+
new PerformanceObserver((entryList) => {
15+
const entries = entryList.getEntries();
16+
const lastEntry = entries[entries.length - 1];
17+
resolve(lastEntry.duration);
18+
}).observe({type: 'largest-contentful-paint', buffered: true});
19+
});
20+
}
21+
822
export const benchmark = async (page: Page, target: string) => {
9-
const pageLoadTimes = [];
10-
let start;
23+
const pageLoadTimes: number[] = [];
1124
for (let i = 0; i < 3; i++) {
12-
start = performance.now();
13-
await page.goto(target);
14-
await page.waitForLoadState('load');
15-
pageLoadTimes.push(performance.now() - start);
25+
await page.goto(target, { waitUntil: 'load' });
26+
pageLoadTimes.push(await page.evaluate(lcpTime));
1627
}
1728
const sumPageLoadTimes = pageLoadTimes.reduce((sum, cur) => sum + cur, 0);
1829
console.log(sumPageLoadTimes);

0 commit comments

Comments
 (0)