Skip to content

@ogygia/testing

Page load

ogygia.page() returns the page load as the browser measured it, with its web vitals, each island's wake, the main thread and the Page tab's findings, so a test can hold a page to a budget.

On this page

ogygia.page() returns what the dock’s Page tab shows for the page in front of the test: the web vitals, each island from the start of its wake to the moment it could respond, the render-blocking files, the bytes by type, the main thread’s long tasks and CPU, and the findings. You call it after page.goto, and hold the report to a budget or to no findings.

import { test, expect } from './fixtures';

test('the home page loads within budget', async ({
  page,
  ogygia
}) => {
  await page.goto('/');
  const load = await ogygia.page();

  expect(load).toMeetBudget({
    lcp: 2500,
    cls: 0.1,
    islandWakeMs: 300
  });
  expect(load).toHaveNoFindings({
    severity: 'warn',
    ignore: ['eager-offscreen']
  });
});

Settling

page(), hydration() and record() each wait for the page to settle before they measure: no island waking or hydrating, no island mounted, woke or hydrated for 300 ms, and the document fully loaded. They wait at most 10 seconds and then measure what’s there, so a page that never settles still gets a report.

When your own steps need the same wait, for example before a screenshot or a click on an island, call ogygia.settled(). It takes quiet (how long no island may mount, wake or hydrate, default 300 ms) and timeout (default 10,000 ms), and resolves to true once the page settled or false if the timeout passed first. A woken island still downloading its code counts as waking, and a hole counts until it answered or finally failed.

import { test, expect } from './fixtures';

test('the carousel is ready before its screenshot', async ({
  page,
  ogygia
}) => {
  await page.goto('/gallery');
  await page
    .getByRole('region', { name: 'Gallery' })
    .scrollIntoViewIfNeeded();
  expect(
    await ogygia.settled({ quiet: 500, timeout: 15_000 })
  ).toBe(true);
  await expect(page).toHaveScreenshot();
});

Report

Every field of the report is plain JSON:

FieldWhat it holds
kind'page'.
urlThe path measured.
routeThe SvelteKit route id the server rendered (/[lang]/about-us), read from the document’s og-route Server-Timing. Set on a build that lists the dock, for a browser with the switch on; null with testing() alone, on the dev server and before engine 3.
nav{ to, t } after an in-app navigation, else null. The report then covers only what happened since that navigation.
vitalsEach measured vital as { key, label, value, rating }: ttfb, fcp, lcp, cls and inp, each when the browser measured it. Times are in ms, and rating is good, fair or poor.
islandsEach island that woke: name, wake, t0 and done on the page’s clock, load_ms, queue_ms, hydrate_ms, the shift and longtask_ms it caused, early_ms when a click beat it, below_fold, cpu_ms.
findingsThe Page tab’s findings, each with code, severity, message and names, the islands it points at.
blockingRender-blocking files: { url, ms, bytes }.
bytesBytes by type: { type, count, transfer, size }.
longtask_msThe total of the page load’s long tasks.
cpuThe main-thread sampler’s summary, { busy_ms, by_kind, fns }, or null when the browser couldn’t sample, the app doesn’t list the dock, the sampler is still recording (it runs for about 8 seconds after the load, longer, up to 20, while islands are still waking), or the page navigated since its load. fns keeps the cpuFunctions hottest (15 by default).
unmeasuredWhat this browser can’t measure, such as layout shifts or the CPU sampler in WebKit. A finding that needs one can’t appear, whatever the page does.
selfWhat ogygia’s own measuring cost (Measuring cost).
engine{ version, lean }, the engine that answered (Engine versions).

The findings are the ones listed under Page findings, with the same codes, so you can match or ignore one by its code. Three are worked out by the dock’s tab only and never appear in page(): island-files-uncached, css-unscoped and css-unmatched (#2304).

import { test, expect } from './fixtures';

test('no island hydrates below the fold on load', async ({
  page,
  ogygia
}) => {
  await page.goto('/');
  const load = await ogygia.page();
  const eager = load.islands
    .filter((i) => i.below_fold)
    .map((i) => i.name);
  expect(eager).toEqual([]);
});

Budget lines

toMeetBudget() reads these lines from a page report. A line you leave out isn’t checked, and a line with nothing measured (no LCP in WebKit, say) fails rather than passes.

LinePasses when
lcpLargest Contentful Paint is at most this many ms.
fcpFirst Contentful Paint is at most this many ms.
clsCumulative Layout Shift is at most this value.
inpInteraction to Next Paint is at most this many ms.
ttfbTime to first byte is at most this many ms.
longTaskMsThe page load’s long tasks add up to at most this many ms.
islandWakeMsThe slowest island took at most this many ms from wake to ready (0 if none woke).

Matchers and budgets has every line for every report.

Browser support

Chromium measures everything. Firefox and WebKit lack some timings, and unmeasured lists them, so an empty findings there means less. Run the budget checks that depend on layout shifts, long tasks or CPU in Chromium. Browser support lists what each kind of timing feeds.

import { test, expect } from './fixtures';

test('layout stays put', async ({
  page,
  ogygia,
  browserName
}) => {
  test.skip(
    browserName !== 'chromium',
    'layout shifts are measured in Chromium'
  );
  await page.goto('/');
  expect(await ogygia.page()).toMeetBudget({ cls: 0.05 });
});