// Run against a local "npm run dev"; requires the optional Playwright package. const path = require('node:path'); const fs = require('node:fs'); const assert = require('node:assert/strict'); const { chromium } = require('playwright'); const out = path.resolve(process.argv[2] || 'proof'); const base = process.argv[3] || 'http://localhost:8788'; const pages = ['/', '/volunteer/', '/moderators/', '/careers/', '/help/', '/privacy/', '/terms/']; (async () => { fs.mkdirSync(out, { recursive: true }); const browser = await chromium.launch(process.env.PW_CHROME ? { executablePath: process.env.PW_CHROME } : {}); try { for (const width of [390, 1366]) { const page = await browser.newPage({ viewport: { width, height: 900 } }); const errors = []; page.on('pageerror', err => errors.push(err.message)); for (const route of pages) { const response = await page.goto(base + route); assert.equal(response.status(), 200, route); assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth + 1), `Overflow: ${route} at ${width}`); await page.screenshot({ path: path.join(out, (route.replaceAll('/', '') || 'home') + '-' + width + '.png'), fullPage: true }); } if (width === 390) { for (const [route, selectors] of [ ['/', ['.nav nav a:not(.nav-hide-sm)', '.getting-started .button', '.footer nav a']], ['/volunteer/', ['.workstreams .tags a', '.app-support-index a', '.app-support-actions a', '.board .job h3 a', '.volunteer-learning summary']], ['/careers/', ['.career-filters input', '.career-filters select', '.career-family a', '.career-family button']], ]) { await page.goto(base + route); for (const selector of selectors) { const heights = await page.locator(selector).evaluateAll(nodes => nodes .map(node => node.getBoundingClientRect().height).filter(Boolean)); assert.ok(heights.length && heights.every(height => height >= 44), route + ' ' + selector); } } await page.locator('#career-query').fill('electrician'); const result = page.locator('#career-results .role-art').first(); await result.scrollIntoViewIfNeeded(); assert.ok(await result.evaluate(img => img.loading === 'lazy' && img.alt === '')); await page.waitForFunction(img => img.complete && img.naturalWidth === 224, await result.elementHandle()); await page.goto(base + '/volunteer/'); const volunteerArt = page.locator('.volunteer-board .role-art').first(); await volunteerArt.scrollIntoViewIfNeeded(); await page.waitForFunction(img => img.complete && img.naturalWidth === 224, await volunteerArt.elementHandle()); await page.goto(base + '/careers/families/11/'); const card = page.locator('.career-guide-card').first(); const link = card.locator('a'); const tile = await card.boundingBox(); const target = await link.boundingBox(); assert.deepEqual(target, tile, 'career guide link fills the whole card'); const href = await link.getAttribute('href'); await link.click({ position: { x: target.width - 10, y: target.height - 10 } }); assert.equal(new URL(page.url()).pathname, href); } for (const oldRoute of ['/jobs/', '/jobs/j_example', '/candidates/?job=j_example', '/download/', '/apps']) { await page.goto(base + oldRoute); assert.equal(new URL(page.url()).pathname, '/volunteer/'); } assert.equal(await page.locator('a[aria-label^="Volunteer:"]').count(), 131); await page.goto(base + '/mcp/'); assert.equal(new URL(page.url()).pathname, '/help/'); for (const retired of ['/appcast.xml', '/appcast-legacy.xml', '/downloads/Jobley-0.1.1.dmg']) { const res = await page.request.get(base + retired, { headers: { 'Cache-Control': 'no-cache' } }); assert.equal(res.status(), 410, retired); assert.equal(res.headers()['cache-control'], 'no-store'); } assert.deepEqual(errors, []); await page.close(); } } finally { await browser.close(); } })().catch(err => { console.error(err); process.exitCode = 1; });