/** * The sign-in form is the one form on the site a stranger has to get through, * and the way it goes wrong is silent. * * It minted `handle-N` ids so that "labels need an id to point at" — and no * label was ever written. Nothing pointed at the id, so the field's only * accessible name was its placeholder: a name that disappears the moment * anyone types, and that asks a voice-control user to say * "yourname.bsky.social" to reach the box. Lighthouse scores the page 100 * either way, because a placeholder does technically produce a name. * * The dialog around it had the matching hole: `` with no * aria-labelledby is announced as "dialog" and nothing else, at the one moment * a player needs telling what took over the screen. * * Both are structural. Nothing errors, both render, and the only way to see * either is to read the accessibility tree. So this reads the source instead. * * Run with `npm test`. */ import { test } from "node:test"; import assert from "node:assert/strict"; import { readFile } from "node:fs/promises"; import { fileURLToPath } from "node:url"; const src = fileURLToPath(new URL("../src/", import.meta.url)); const form = await readFile(`${src}signin-form.ts`, "utf8"); const modal = await readFile(`${src}signin-modal.ts`, "utf8"); // An id earns its keep by being pointed at, not by being set. `id` was set on // the input from the day it was minted, so "is it referenced?" was always yes // and the missing label still went unnoticed for as long as it did. const POINTERS = ["htmlFor", '"aria-describedby"', '"aria-labelledby"']; test("every id the form mints is pointed at, not just set", () => { // The bare `id` the input takes, plus `const blurbId`, `const headingId`. assert.match(form, /const id = `handle-/, "the handle field's id moved"); const minted = [ "id", ...[...form.matchAll(/const (\w+Id) =/g)].map((m) => m[1]), ]; const both = `${form}\n${modal}`; for (const name of minted) { const pointedAt = POINTERS.some((attr) => new RegExp(`${attr}: ${name}\\b`).test(both), ); assert.ok( pointedAt, `${name} is minted but nothing points at it with ${POINTERS.join(" / ")} — ` + `which is how the handle field went without a label`, ); } }); test("the handle field is named by a label, not by its placeholder", () => { assert.match( form, /el\("label",\s*\{[^}]*htmlFor: id/, "no