@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.
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/testimport { 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.
| Call | What it returns | Page |
|---|---|---|
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.
| Runner | How | What you get |
|---|---|---|
| Playwright Test | withOgygia(test, expect) | Everything: the fixture, the matchers, blockNavigation, request tagging and ogygia.json reports. |
| Playwright without the fixture | new Ogygia(playwrightDriver(page)) | The same measurements for pages you manage yourself, such as two browser contexts in one test. |
| Puppeteer, WebdriverIO, others | new Ogygia(driver) with an OgygiaDriver | The 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 script | compare(), 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
| Page | What it covers |
|---|---|
| Setup | testing(), the Playwright fixture, every fixture option, builds, lean testing, measuring cost and engine versions. |
| Page load | page(), every field of its report, waiting for the page to settle, and the page budget lines. |
| Hydration checks | hydration(), the six statuses, instance keys, the kinds of change, ignoreAttributes and toHydrateCleanly(). |
| Session recording | record(), recordings across pages, blockNavigation, the server side of a session, and the session budget lines. |
| Server profiles | profile(), its options, what a profile holds, and keeping profiles comparable in CI. |
| Matchers and budgets | toHaveNoFindings(), toMeetBudget(), toHydrateCleanly(), checkBudget() and every budget line. |
| CI reports | The ogygia.json attachment, forAttachment(), compare(), toMarkdown(), noise and several runs a side. |
| Other runners | new Ogygia(driver), the driver contract, Puppeteer, Vitest and Jest, playwrightDriver() and turnOnDevtools(). |
@ogygia/testing | The generated API reference. |
Integrations
- @ogygia/devtools measures the same things in the dock:
page()is the Page tab,hydration()the Hydration tab andrecord()the Record tab, with the same finding codes. Its profiler is whatprofile()andrecord(…, { server: true })read. - Regions are what
hydration()andrecord()report on: each island by name and instance (Carousel#2), witht0anddone, the times it began to wake and could respond. One report therefore tells you which step of a session woke aninteractionisland. - @ogygia/cli covers the same ground without a test suite:
npx ogygia perfjudges 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:
- Playwright, in Setup
- Changed, but how?, in Hydration checks
- What measuring costs, and lean testing, in Setup
- When the site runs an older ogygia, in Setup
- Server measurements, in Session recording
- CI profiles, in Server profiles
- Matchers, in Matchers and budgets
- Reports in CI, in CI reports
- Several runs a side, in CI reports
- Other runners, in Other runners