#!/usr/bin/env bun /** * A select near the bottom of the window flips its menu above the field and * caps it. The selected option has to sit inside that popup. * * Measured 2026-11-26, filled and outlined, 16 options, the second selected * (`data-id="1"`): a 495px spacer, the menu mounted on document.body with * max-height 280px, the field at y 519–575, the popup at y 239–519, the * selected option at y −173 (scrollTop 462) with no overlap. * * The page uses that setup. After the menu has opened and its reveal has * finished, the selected option's box intersects the popup, and the popup * is above the field. On main the option stays above the popup, so this * fails there. Run on main and on the branch: * * bun run scripts/check-select-flipped-option.ts */ import assert from "node:assert/strict"; import { resolve } from "node:path"; import * as sass from "sass"; import { launchChromium } from "./browser-profile"; import { directionArmsPrelude, sassOptions } from "./build-styles"; const bundle = await Bun.build({ entrypoints: [resolve("src/components/select/index.ts")], target: "browser", format: "esm", minify: true, }); assert(bundle.success, String(bundle.logs)); const js = (await bundle.outputs[0]!.text()).replaceAll("\u0000", "\\u0000"); const css = sass.compileString( directionArmsPrelude() + (await Bun.file("src/styles/main.scss").text()), sassOptions(), ).css; const server = Bun.serve({ hostname: "127.0.0.1", port: 0, fetch(request) { const path = new URL(request.url).pathname; if (path === "/select.js") { return new Response(js, { headers: { "Content-Type": "text/javascript" } }); } if (path === "/styles.css") { return new Response(css, { headers: { "Content-Type": "text/css" } }); } return new Response( `
`, { headers: { "Content-Type": "text/html" } }, ); }, }); type Box = { top: number; right: number; bottom: number; left: number; width: number; height: number }; const browser = await launchChromium({ headless: true }); try { const page = await browser.newPage(); await page.setViewportSize({ width: 1280, height: 640 }); await page.goto(`http://127.0.0.1:${server.port}/`); await page.waitForFunction(() => (window as unknown as { ready?: boolean }).ready === true); const options = Array.from({ length: 16 }, (_, index) => ({ id: String(index), text: `Option ${index}` })); for (const variant of ["filled", "outlined"] as const) { const boxes = await page.evaluate(async ({ variant, options }) => { const host = document.querySelector("#host")!; host.replaceChildren(); const win = window as unknown as { createSelect: (config: Record