Skip to content

Commit b9ade6a

Browse files
chore: add lazy load images snippet
1 parent 1054aed commit b9ade6a

File tree

3 files changed

+15
-59
lines changed

3 files changed

+15
-59
lines changed

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"baseUrl": "src",
1313
"lib": [
1414
"dom",
15+
"dom.iterable",
1516
"es2015",
1617
"es2017",
1718
"es2020"

visual-regression-example/test/visual/google.visual.spec.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {test, expect} from '@playwright/test';
1+
import {test, expect, Page} from '@playwright/test';
22

33
test.describe('Google Visual Regression Test', () => {
44
test('google.it homepage should match visual baseline', async ({page}) => {
@@ -12,8 +12,21 @@ test.describe('Google Visual Regression Test', () => {
1212
content: `#hplogo { display: none !important; }`,
1313
});
1414

15+
// Force to load the lazy images:
16+
await forceLoadLazyImages(page)
17+
1518
await page.waitForLoadState('networkidle');
1619

1720
await expect(page).toHaveScreenshot('google-homepage.png');
1821
});
1922
});
23+
24+
25+
async function forceLoadLazyImages(page: Page): Promise<void> {
26+
const images = document.querySelectorAll('img[loading="lazy"]');
27+
return page.evaluate(() => {
28+
for (const image of images) {
29+
image.setAttribute('loading', 'eager');
30+
}
31+
});
32+
}

visual-regression-example/tsconfig.json

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)