diff --git a/.gitignore b/.gitignore index dde83d6..fcf7c53 100644 --- a/.gitignore +++ b/.gitignore @@ -54,4 +54,7 @@ node_modules/ .wrangler # Import cache -.import-cache/ \ No newline at end of file +.import-cache/ + +# Visual diff screenshots +.visual-diff/ \ No newline at end of file diff --git a/package.json b/package.json index 412a612..e22999a 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,8 @@ "start": "cross-env NODE_OPTIONS=--no-deprecation next start", "test": "pnpm run test:int && pnpm run test:e2e", "test:e2e": "cross-env NODE_OPTIONS=\"--no-deprecation --import=tsx/esm\" playwright test --config=playwright.config.ts", - "test:int": "cross-env NODE_OPTIONS=--no-deprecation vitest run --config ./vitest.config.mts" + "test:int": "cross-env NODE_OPTIONS=--no-deprecation vitest run --config ./vitest.config.mts", + "visual:diff": "cross-env NODE_OPTIONS=\"--no-deprecation --import=tsx/esm\" tsx scripts/visual-diff.ts" }, "dependencies": { "@fontsource-variable/inter": "^5.2.8", diff --git a/scripts/visual-diff.ts b/scripts/visual-diff.ts new file mode 100644 index 0000000..384cad4 --- /dev/null +++ b/scripts/visual-diff.ts @@ -0,0 +1,45 @@ +// scripts/visual-diff.ts +import { chromium } from '@playwright/test' +import { mkdir } from 'node:fs/promises' + +const URLS = [ + '/', + '/blog/', + '/blog/a-guide-to-laravel-authorization-patterns/', + '/blog/feedback-loops-in-an-AI-era/', + '/blog/im-free/', + '/projects/', + '/projects/bully/', + '/tags/', + '/about/', + '/hire-me/', +] + +const NEW_BASE = process.env.PLAYWRIGHT_BASE_URL ?? 'http://localhost:3001' + +async function main() { + await mkdir('.visual-diff/old', { recursive: true }) + await mkdir('.visual-diff/new', { recursive: true }) + const browser = await chromium.launch() + const ctx = await browser.newContext({ viewport: { width: 1280, height: 800 } }) + const page = await ctx.newPage() + for (const url of URLS) { + const file = url.replace(/\W+/g, '_').replace(/^_|_$/g, '') || 'home' + console.log(`Capturing: ${url}`) + try { + await page.goto('https://arter.dev' + url, { waitUntil: 'networkidle', timeout: 30000 }) + await page.screenshot({ path: `.visual-diff/old/${file}.png`, fullPage: true }) + } catch (e) { + console.error(` [WARN] Failed to capture old site for ${url}: ${(e as Error).message}`) + } + try { + await page.goto(NEW_BASE + url, { waitUntil: 'networkidle', timeout: 30000 }) + await page.screenshot({ path: `.visual-diff/new/${file}.png`, fullPage: true }) + } catch (e) { + console.error(` [WARN] Failed to capture new site for ${url}: ${(e as Error).message}`) + } + } + await browser.close() + console.log('Visual diff screenshots written to .visual-diff/{old,new}') +} +main().catch((e) => { console.error(e); process.exit(1) })