chadtmiller.com/knotless

Git hosted in your atproto account, on any stock PDS, fast enough for agents.

git clone knotless://chadtmiller.com/knotless

needs the knotless git helper. set it up

main
43 lines · 2.1 KB Raw History
// 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 the HTML it was taken from, and setup.mjs lists
// the pages whose HTML still matches in every project: those are skipped
// as unchanged, before a browser page is opened. SHOTS_ALL=1 takes every
// one regardless, as `just shots-check` does.

import { test, expect } from '@playwright/test'
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { digest } from './digest.mjs'

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 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, request }, info) => {
      const path = read('views.json', {})[name]
      const sum = digest(await (await request.get(path)).text())
      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:
      // it is covered, so the rest can match to the pixel.
      await expect(page).toHaveScreenshot(`${name}.png`, { fullPage: true, mask: [page.locator('.did')], maskColor: '#80808a' })
      writeFileSync(info.snapshotPath(`${name}.sha256`), sum)
    })
  })
}