// The site (site/index.html) never scrolls sideways: at every viewport width from 320 to 1440 px (10 px steps), in the // light and the dark theme, document.documentElement.scrollWidth stays within innerWidth. On a failure it names the // elements whose right edge passes the viewport outside any scroll container (pseudo-elements show as their owner). // Uses the bundled playwright-core with its Chromium (or Google Chrome); skips when neither can launch. import { afterAll, describe, expect, test } from 'bun:test'; import { join } from 'node:path'; const page = 'file://' + join(import.meta.dir, '..', 'site', 'index.html'); // eslint-disable-next-line @typescript-eslint/no-explicit-any let browser: any = null; let skipWhy = ''; try { const { chromium } = await import('playwright-core'); try { browser = await chromium.launch({ headless: true }); } catch { browser = await chromium.launch({ headless: true, channel: 'chrome' }); } } catch (e) { skipWhy = (e as Error).message.split('\n')[0]!; } if (!browser) console.warn(`site overflow test skipped: no Chromium could launch (${skipWhy}). Run \`bunx playwright install chromium\`.`); afterAll(async () => { await browser?.close(); }); describe.skipIf(!browser)('site: no horizontal overflow', () => { for (const scheme of ['light', 'dark'] as const) { test(`320-1440 px, ${scheme}`, async () => { const ctx = await browser.newContext({ colorScheme: scheme, viewport: { width: 1440, height: 900 } }); const p = await ctx.newPage(); await p.goto(page, { waitUntil: 'load' }); const bad: string[] = []; for (let w = 320; w <= 1440; w += 10) { await p.setViewportSize({ width: w, height: 900 }); const r = await p.evaluate(() => { const iw = innerWidth, sw = document.documentElement.scrollWidth; if (sw <= iw) return null; const els: string[] = []; for (const el of document.querySelectorAll('body *')) { const rc = el.getBoundingClientRect(); if (rc.width === 0 || rc.right <= iw + 0.5) continue; let clipped = false; for (let a = el.parentElement; a && a !== document.body; a = a.parentElement) { if (getComputedStyle(a).overflowX !== 'visible') { clipped = true; break; } } if (!clipped) els.push(`${el.tagName.toLowerCase()}${el.id ? '#' + el.id : ''}${[...el.classList].map(c => '.' + c).join('')} right=${Math.round(rc.right)}`); } return `${iw}px: page ${sw - iw}px too wide${els.length ? ' (' + els.slice(0, 5).join(', ') + ')' : ' (a pseudo-element or transform)'}`; }); if (r) bad.push(r); } await ctx.close(); expect(bad).toEqual([]); }, 120_000); } });