// One screenshot per page, per project in playwright.config.mjs. The pages' // paths are known once setup.mjs has made them, so they are read in each test. // // A page's pixels follow from its HTML and the browser. Beside each // baseline is a digest of both it was taken from, and setup.mjs lists // the pages whose digest still matches in every project: those are skipped // as unchanged, before a browser page is opened. SHOTS_ALL=1 takes every // one regardless. import { test, expect } from '@playwright/test' import { existsSync, readFileSync, writeFileSync } from 'node:fs' import { dirname, resolve } from 'node:path' import { fileURLToPath } from 'node:url' const root = resolve(dirname(fileURLToPath(import.meta.url)), '../..') const read = (file, otherwise) => { const path = resolve(root, 'target/shots', file) return existsSync(path) ? JSON.parse(readFileSync(path, 'utf8')) : otherwise } const unchanged = new Set(read('unchanged.json', [])) const sums = read('sums.json', {}) const names = [ 'home', 'search', 'start', 'profile', 'profile-fork', 'repository', 'directory', 'file', 'markdown', 'image', 'commits', 'commit', 'pulls', 'pulls-closed', 'pull', 'pull-open', 'issues', 'issues-closed', 'issue', 'issue-closed', 'fork', 'empty', 'missing', ] for (const name of names) { test.describe(() => { test.skip(unchanged.has(name), 'unchanged') test(name, async ({ page }, info) => { const path = read('views.json', {})[name] await page.goto(path, { waitUntil: 'load' }) // The pages paint their highlighting once they are running. await page.locator('html[data-ready]').waitFor({ state: 'attached' }) // A DID is new each run, as the PLC directory makes one per account, // and a command naming this server names the port it is on: they are // covered, so the rest can match to the pixel. const mask = [page.locator('.did'), page.locator('.cmd', { hasText: /127\.0\.0\.1:\d+/ })] await expect(page).toHaveScreenshot(`${name}.png`, { fullPage: true, mask, maskColor: '#80808a' }) writeFileSync(info.snapshotPath(`${name}.sha256`), sums[name]) }) }) }