Skip to content

Commit

Permalink
Add LCP test
Browse files Browse the repository at this point in the history
  • Loading branch information
tunetheweb committed Nov 6, 2024
1 parent 5b8df6f commit ab1cb3a
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/e2e/onLCP-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,48 @@ describe('onLCP()', async function () {
assert.equal(lcp2.attribution.lcpResourceEntry, undefined);
assert.equal(lcp2.attribution.lcpEntry, undefined);
});

it('reports the target when removed (reportAllChanges === false)', async function () {
if (!browserSupportsLCP) this.skip();

await navigateTo('/test/lcp?attribution=1');

// Wait until all images are loaded and fully rendered.
await imagesPainted();

await browser.execute(() => {
document.querySelector('img').remove();
});

// Load a new page to trigger the hidden state.
await navigateTo('about:blank');

const [lcp] = await getBeacons();
assertStandardReportsAreCorrect([lcp]);
assert.equal(lcp.attribution.element, 'img.bar.foo');
});

it('reports the target when removed (reportAllChanges === true)', async function () {
if (!browserSupportsLCP) this.skip();

await navigateTo('/test/lcp?attribution=1&reportAllChanges=1');

// Wait until all images are loaded and fully rendered.
await imagesPainted();

await browser.execute(() => {
document.querySelector('img').remove();
});

// Load a new page to trigger the hidden state.
await navigateTo('about:blank');

await beaconCountIs(2);
const [lcp1, lcp2] = await getBeacons();
assertFullReportsAreCorrect([lcp1, lcp2]);
assert.equal(lcp1.attribution.element, 'html>body>main>h1');
assert.equal(lcp2.attribution.element, 'html>body>main>p>img.bar.foo');
});
});
});

Expand Down

0 comments on commit ab1cb3a

Please sign in to comment.