Skip to content

@ogygia/testing

Testing

@ogygia/testing turns what the devtools and the SSR profiler measure into test checks. Your Playwright tests click through the app as they already do, and fail when hydration breaks, an interaction gets slow or a page misses its budget.

On this page

A performance problem you find by hand in the devtools tends to come back a few releases later, because nothing checks for it. @ogygia/testing lets your tests use what the devtools and the SSR profiler measure. Your tests drive the app as they already do, ogygia measures what happened, and the test asserts on the result.

It works in two halves. The app under test lists the testing() plugin. The test side injects a small testing engine into every page it opens, and the plugin hands the engine the runtime’s hooks: which island woke, which one hydrated, what failed. A visitor’s browser has no engine, so for them each hook is one global read that finds nothing.

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

test('checkout stays fast', async ({ page, ogygia }) => {
  await page.goto('/cart');
  expect(await ogygia.page()).toMeetBudget({
    lcp: 2500,
    cls: 0.1
  });
  expect(await ogygia.hydration()).toHydrateCleanly();
});

Installation

Install the package next to Playwright, and list testing() from @ogygia/testing/vite beside ogygia(), before sveltekit(). Most apps list it only for the server their tests run against, behind an environment switch. List devtools({ profiler: true }) from @ogygia/devtools beside it for profile() and the server side of a recording; its dock also lets the page sample its main thread. Hydration and session checks need only testing() (what each setup measures).

Setup covers the dev server and builds, every fixture option, lean testing and what to do when the testing API doesn’t answer.

pnpm add -D @ogygia/testing @playwright/test
import { sveltekit } from '@sveltejs/kit/vite';
import { ogygia } from 'ogygia/vite';
import { testing } from '@ogygia/testing/vite';
import { devtools } from '@ogygia/devtools/vite';
import { defineConfig } from 'vite';

const e2e = !!process.env.E2E;

export default defineConfig({
  plugins: [
    ogygia(),
    ...(e2e
      ? [
          testing(),
          devtools({ profiler: true })
        ]
      : []),
    sveltekit()
  ]
});

First test

ogygia doesn’t import Playwright itself, so you hand it your own test and expect. withOgygia returns them with an ogygia fixture added and ogygia’s matchers on expect. Import both from this file in every spec.

import {
  test as base,
  expect as baseExpect
} from '@playwright/test';
import { withOgygia } from '@ogygia/testing';

export const { test, expect } = withOgygia(base, baseExpect);
import { test, expect } from './fixtures';

test('buying stays quick', async ({ page, ogygia }) => {
  await page.goto('/cart');

  const session = await ogygia.record(async () => {
    await page.getByRole('button', { name: 'Buy' }).click();
  });
  expect(session).toHaveNoFindings({ severity: 'warn' });
  expect(session).toMeetBudget({
    maxInteractionMs: 200,
    errors: 0
  });

  expect(await ogygia.profile('/cart')).toMeetBudget({
    score: 80,
    renderMs: 200
  });
});

Primitives

The fixture gives you four measurements and a wait. Each measurement returns a plain JSON report, and each report is kept for the test’s attachment.

CallWhat it returnsPage
ogygia.page()The page load as the browser measured it: vitals, each island’s wake, the main thread and the findings of the Page tab.Page load
ogygia.hydration()Each island’s hydration status, with the difference for one whose markup changed.Hydration checks
ogygia.record(actions)What your actions did: slow interactions, dead clicks, requests, long tasks, shifts and errors, and the server’s side.Session recording
ogygia.profile(path)The SSR profiler’s report for a path: score, forecast, findings, render times and page weight.Server profiles
ogygia.settled()true once no island is waking or hydrating, false if its timeout passed first.Page load

Runners

The package runs in Node: the test side reads the engine from its own files and hands it to the browser. Which parts you get depends on the runner and the page driver.

RunnerHowWhat you get
Playwright TestwithOgygia(test, expect)Everything: the fixture, the matchers, blockNavigation, request tagging and ogygia.json reports.
Playwright without the fixturenew Ogygia(playwrightDriver(page))The same measurements for pages you manage yourself, such as two browser contexts in one test.
Puppeteer, WebdriverIO, othersnew Ogygia(driver) with an OgygiaDriverThe measurements. blockNavigation and request tagging only if your driver implements them.
Vitest or Jest (Node)expect.extend(ogygiaMatchers)The matchers, over reports from any driver or from saved ogygia.json files.
A plain Node scriptcompare(), toMarkdown(), checkBudget()Diffs between two CI runs and budget lines as data.

Vitest’s browser mode runs the test file inside the page, where there’s no file system for the engine and no driver to load other pages, so use a Node-side runner. Other runners shows each setup.

Package contents

PageWhat it covers
Setuptesting(), the Playwright fixture, every fixture option, builds, lean testing, measuring cost and engine versions.
Page loadpage(), every field of its report, waiting for the page to settle, and the page budget lines.
Hydration checkshydration(), the six statuses, instance keys, the kinds of change, ignoreAttributes and toHydrateCleanly().
Session recordingrecord(), recordings across pages, blockNavigation, the server side of a session, and the session budget lines.
Server profilesprofile(), its options, what a profile holds, and keeping profiles comparable in CI.
Matchers and budgetstoHaveNoFindings(), toMeetBudget(), toHydrateCleanly(), checkBudget() and every budget line.
CI reportsThe ogygia.json attachment, forAttachment(), compare(), toMarkdown(), noise and several runs a side.
Other runnersnew Ogygia(driver), the driver contract, Puppeteer, Vitest and Jest, playwrightDriver() and turnOnDevtools().
@ogygia/testingThe generated API reference.

Integrations

  • @ogygia/devtools measures the same things in the dock: page() is the Page tab, hydration() the Hydration tab and record() the Record tab, with the same finding codes. Its profiler is what profile() and record(…, { server: true }) read.
  • Regions are what hydration() and record() report on: each island by name and instance (Carousel#2), with t0 and done, the times it began to wake and could respond. One report therefore tells you which step of a session woke an interaction island.
  • @ogygia/cli covers the same ground without a test suite: npx ogygia perf judges a list of pages against a budget file in CI.

Moved sections

These sections used to be on the single Testing page. Each now lives on its own page: