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
35 lines · 1.6 KB Raw History
// The social card each page in world.cards names, compared pixel for pixel
// with the one checked in. A card's URL carries a hash of what it shows:
// beside each baseline is a digest of it, and setup.mjs lists the cards
// whose URL is as it was, skipped as unchanged as the pages are.

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 { card, 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', []))
// Null when the pages are drawn from fixtures, which hold no cards to draw.
const cards = read('cards.json', null)

const names = ['home', 'repository', 'notes', 'pull', 'pull-open', 'issue', 'issue-closed']

for (const name of names) {
  test.describe(() => {
    test.skip(!cards, 'knotless-serve draws the cards: `just shots-live`')
    test.skip(unchanged.has(`card:${name}`), 'unchanged')
    test(name, async ({ request }, info) => {
      const path = card(await (await request.get(cards[name])).text())
      const png = await request.get(path)
      expect(png.headers()['content-type']).toBe('image/png')
      expect(await png.body()).toMatchSnapshot(`${name}.png`)
      writeFileSync(info.snapshotPath(`${name}.sha256`), digest(path))
    })
  })
}