Something went wrong. Try again.
My website. cameron.stream
Something went wrong. Try again.
JavaScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556// LINKS_PLAYWRIGHT=/path/to/playwright/index.mjs node scripts/test-links-browser.mjs [base] [receipts]import assert from "node:assert/strict";import { mkdir, writeFile } from "node:fs/promises";import { pathToFileURL } from "node:url";const { chromium } = await import(process.env.LINKS_PLAYWRIGHT ? pathToFileURL(process.env.LINKS_PLAYWRIGHT).href : "playwright");const base = process.argv[2] || "http://127.0.0.1:3197";const receipts = process.argv[3] || "/tmp/cameron-links-browser";await mkdir(receipts, { recursive: true });const browser = await chromium.launch({ headless: true, executablePath: process.env.LINKS_CHROME });const results = [];try { for (const width of [320, 390, 1280]) { const page = await browser.newPage({ viewport: { width, height: 844 } }); const errors = []; page.on("pageerror", (error) => errors.push(error.message)); await page.goto(`${base}/other`, { waitUntil: "networkidle" }); await page.getByRole("navigation", { name: "Other pages" }).getByRole("link", { name: /Links/ }).click(); await page.waitForURL(`${base}/links`); await page.getByRole("list", { name: "Saved links" }).waitFor(); assert.equal(await page.title(), "Links — Cameron's website"); assert.equal(await page.locator('a[aria-current="page"]').textContent(), "Other"); const count = await page.locator('main li a').count(); assert.ok(count > 0, "Public bookmarks loaded"); assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), "No horizontal overflow"); for (const theme of ["light", "dark"]) { if (width <= 680) { await page.locator(`[data-theme-choice="${theme}"]`).click(); assert.equal(await page.locator("html").getAttribute("data-theme"), theme); } else { const current = await page.locator("html").getAttribute("data-theme") || "light"; if (current !== theme) await page.locator("#theme-toggle").click(); assert.equal(await page.locator("html").getAttribute("data-theme") || "light", theme); } await page.evaluate(() => scrollTo(0, 0)); await page.screenshot({ path: `${receipts}/${width}-${theme}.png` }); } const hrefs = await page.locator('main a').evaluateAll((anchors) => anchors.map((a) => a.href)); assert.ok(hrefs.every((href) => /^https?:/.test(href))); for (const path of ["/links/", "/library", "/semble"]) { const response = await page.goto(`${base}${path}`, { waitUntil: "networkidle" }); assert.equal(response.status(), 200); assert.equal(new URL(page.url()).pathname, "/links"); } assert.deepEqual(errors, []); results.push({ width, bookmarks: count, overflow: false, errors, hrefs }); await page.close(); } const response = await fetch(`${base}/links/?from=about`, { redirect: "manual" }); assert.equal(response.status, 301); assert.equal(response.headers.get("location"), "/links?from=about"); await writeFile(`${receipts}/results.json`, JSON.stringify({ base, results }, null, 2)); console.log(JSON.stringify({ base, receipts, results: results.map(({ hrefs, ...result }) => result) }));} finally { await browser.close();}