- e2e: every section variant in every template (axe and 312 screenshots compared with local baselines), Lighthouse on a phone (median of three, CPU slowdown calibrated to the machine), the whole suite on real Postgres with E2E_DATABASE_URL, a frozen clock, E2E_REUSE for running servers. - Fixes found by them: contrast on Bold's service times panel and Calendar event dates; the OpenStreetMap embed loads only once on screen; the messages page's first thumbnail is eager, its host preconnected. - The restore e2e waits for its second publish (raced on Postgres). - docs: Hub 2.22.0 deployed; website@1.0.0 released. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
81 lines
4.2 KiB
TypeScript
81 lines
4.2 KiB
TypeScript
/**
|
||
* Every section variant in every template (WEBSITE-1.0-PLAN §3, "Checks per variant", and §13): the
|
||
* demo church's homepage with all eight sections showing, one variant changed at a time. For each,
|
||
* axe finds no violations (WCAG 2.2 AA) and the section looks as it did last time at phone, tablet
|
||
* and desktop width: 26 variants × 4 templates × 3 widths = 312 screenshots, compared with
|
||
* `toHaveScreenshot` against the baselines in e2e/variants.spec.ts-snapshots/.
|
||
*
|
||
* The baselines aren't in git (about 20 MB, and each operating system draws text a little
|
||
* differently): they're kept on the machine that runs the release checks. Take them at a release
|
||
* (`npx playwright test variants --update-snapshots`, then look through them), and the next
|
||
* release's run shows every section that changed. The e2e server freezes the clock (E2E_NOW), so
|
||
* the demo's dates never change between runs. What comes from outside is masked: the video, the
|
||
* map (OpenStreetMap) and YouTube's thumbnails.
|
||
*/
|
||
import AxeBuilder from "@axe-core/playwright";
|
||
import { expect, test, type Page } from "@playwright/test";
|
||
import { SECTION_TYPES, SECTION_VARIANTS, TEMPLATE_VARIANTS } from "../backend/src/site/variants.js";
|
||
|
||
const BACKEND = "http://127.0.0.1:5310";
|
||
const TEMPLATES = Object.keys(TEMPLATE_VARIANTS) as (keyof typeof TEMPLATE_VARIANTS)[];
|
||
const WIDTHS = [["phone", { width: 390, height: 844 }], ["tablet", { width: 820, height: 1180 }], ["desktop", { width: 1366, height: 900 }]] as const;
|
||
// Every section showing, in a fixed order, so the nth <section> in <main> is the nth type here.
|
||
const HOME = SECTION_TYPES.map((section) => ({ section, hidden: false }));
|
||
|
||
async function design(page: Page, variants: Record<string, string>) {
|
||
const res = await page.request.post(`${BACKEND}/test/design`, { data: { variants, home: HOME } });
|
||
expect(res.ok()).toBeTruthy();
|
||
}
|
||
|
||
/**
|
||
* Lazy images load only once scrolled to: go through the page, then wait for every image. The
|
||
* site's own images must really have loaded (a broken one is "complete" too).
|
||
*/
|
||
async function loadImages(page: Page) {
|
||
await page.evaluate(async () => {
|
||
for (let y = 0; y < document.body.scrollHeight; y += 500) { window.scrollTo(0, y); await new Promise((r) => setTimeout(r, 40)); }
|
||
window.scrollTo(0, 0);
|
||
});
|
||
await page.waitForFunction(() => Array.from(document.images).every((i) => i.complete), null, { timeout: 30_000 });
|
||
const broken = await page.evaluate(() => Array.from(document.images)
|
||
.filter((i) => new URL(i.currentSrc || i.src, location.href).origin === location.origin && i.naturalWidth === 0)
|
||
.map((i) => i.currentSrc || i.src));
|
||
expect(broken, "images that didn't load").toEqual([]);
|
||
}
|
||
|
||
for (const template of TEMPLATES) {
|
||
test.describe(`${template} variants`, () => {
|
||
test.beforeAll(async ({ request }) => {
|
||
expect((await request.post(`${BACKEND}/test/demo?template=${template}`)).ok()).toBeTruthy();
|
||
});
|
||
|
||
for (const [i, type] of SECTION_TYPES.entries()) {
|
||
for (const variant of SECTION_VARIANTS[type]) {
|
||
test(`${type}: ${variant}`, async ({ page }) => {
|
||
await design(page, { [type]: variant });
|
||
await page.setViewportSize(WIDTHS[2][1]);
|
||
expect((await page.goto("/"))?.status()).toBe(200);
|
||
await expect(page.locator("html")).toHaveAttribute("data-template", template);
|
||
const sections = page.locator("main > section");
|
||
await expect(sections).toHaveCount(SECTION_TYPES.length);
|
||
await loadImages(page);
|
||
|
||
const axe = await new AxeBuilder({ page }).withTags(["wcag2a", "wcag2aa", "wcag21aa", "wcag22aa"]).analyze();
|
||
expect(axe.violations.map((v) => `${v.id} (${v.nodes.length}) ${v.nodes[0]?.target}`)).toEqual([]);
|
||
|
||
const section = sections.nth(i);
|
||
for (const [name, size] of WIDTHS) {
|
||
await page.setViewportSize(size);
|
||
await loadImages(page);
|
||
await expect(section).toHaveScreenshot(`${template}-${type}-${variant}-${name}.png`, {
|
||
mask: [page.locator("main video"), page.locator("main [data-map]"), page.locator('main img[src*="ytimg.com"]')],
|
||
animations: "disabled",
|
||
maxDiffPixelRatio: 0.01,
|
||
});
|
||
}
|
||
});
|
||
}
|
||
}
|
||
});
|
||
}
|