// e2e/performance.spec.ts — the project's performance budget gate (iapl-performance skill, docs/performance.md). // Copy this file and perf-lab.mjs (same folder) to e2e/. Runs against the BUILT site: pnpm build && pnpm test:e2e. // It fails when a page breaks a budget: the plugin's defaults (Core Web Vitals "good", bytes, requests), tightened // below to what this site measured, so a change that makes it slower fails. Loosen a number only with a reason. import type { Browser } from '@playwright/test' import { overBudget, perfBudgets } from '@intecion/ipal-kit/doctor' import { chromium, expect, test } from '@playwright/test' // a plain ES module (JSDoc types) — perf-lab.mjs from the skill's resources import { measureMedian } from './perf-lab.mjs' const runs = Number(process.env.PERF_RUNS ?? 1) // Start from the defaults; after the first run, set each number to what you measured plus ~20 % (the lab is noisy). const budgets = perfBudgets({ desktop: {}, mobile: {}, }) // One page of each template the site has (AGENTS.md → Site map). `budget` changes a number for one page, with a reason. const PAGES: Array<{ budget?: Partial; name: string; path: string }> = [ { name: 'home', path: '/pl' }, // { name: 'page', path: '/pl/o-nas' }, // { name: 'post', path: '/pl/blog/' }, // { name: 'form', path: '/pl/kontakt', budget: { thirdParty: ['https://challenges.cloudflare.com'] } }, // Turnstile ] let browser: Browser test.beforeAll(async () => { browser = await chromium.launch() }) test.afterAll(async () => { await browser?.close() }) for (const page of PAGES) { for (const profile of ['mobile', 'desktop'] as const) { test(`${page.name} (${profile}) stays within its performance budget`, async ({ baseURL }) => { test.setTimeout(120_000) // third-party requests are recorded, then aborted: an external host cannot fail or hang the test const measured = await measureMedian(browser, `${baseURL}${page.path}`, profile, runs, { blockThirdParty: true }) test.info().annotations.push({ description: JSON.stringify({ bytes: measured.bytes, cls: measured.cls, inp: measured.inp, lcp: measured.lcp, requests: measured.requests }), type: 'measured' }) expect(overBudget(measured, { ...budgets[profile], ...page.budget }), `${page.path} ${profile}`).toEqual([]) if (measured.lcpElement?.tag === 'img') {expect(measured.lcpElement.loading, 'the LCP image is lazy').not.toBe('lazy')} }) } }