// The social card each page in world.cards names, as knotless-serve draws // it, written to target/shots/cards to look at (`just shots-cards`). Only a // world has cards to draw: from fixtures they are skipped. import { test, expect } from '@playwright/test' import { existsSync, readFileSync } from 'node:fs' import { dirname, resolve } from 'node:path' import { fileURLToPath } from 'node:url' import { card } from './digest.mjs' const root = resolve(dirname(fileURLToPath(import.meta.url)), '../..') const path = resolve(root, 'target/shots/cards.json') // Null when the pages are drawn from fixtures, which hold no cards to draw. const cards = existsSync(path) ? JSON.parse(readFileSync(path, 'utf8')) : 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-cards`') test(name, async ({ request }) => { const png = await request.get(card(await (await request.get(cards[name])).text())) expect(png.headers()['content-type']).toBe('image/png') expect(await png.body()).toMatchSnapshot(`${name}.png`) }) }) }