Skip to content

Commit 1336497

Browse files
committed
test: read either quote style instead of documenting the gap
The comment claimed a double-quoted entry is caught by the sibling orphan test. That holds for a /docs entry but not for the one /ui cross-link, which is not a doc directory, so nothing in the file would have caught a sentence-cased relabel of it. Verified: double-quoting both keys of the /ui entry left labels and hrefs equal at 43, above the floor, with no orphan reported. Rather than document a narrower version of the gap, this closes it. The quote character is captured and back-referenced instead of hard-coded, so both styles parse and a label may carry the other quote inside it. Both shapes that previously escaped now fail the guard by name. Renames IDENTIFIERS to FIXED_CASING. The set was widened to hold brands that start lowercase, and macOS is not an identifier in any sense, so the symbol an author greps for disagreed with the rule it encodes. That was the last place the pre-widening wording survived.
1 parent 488e13b commit 1336497

1 file changed

Lines changed: 21 additions & 18 deletions

File tree

website/test/ssr/docs-links.test.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ test('every docs sidebar label and section title is Title Case', async () => {
244244
// spelling is correct, not a slip". Matched against the
245245
// word with wrapping punctuation stripped, so it survives a rename to
246246
// 'Auth Providers (createAuth API)'.
247-
const IDENTIFIERS = new Set(['createAuth', '@webjsdev/ui']);
247+
const FIXED_CASING = new Set(['createAuth', '@webjsdev/ui']);
248248

249249
const layout = await readFile(resolve(DOCS_ROOT, 'layout.ts'), 'utf8');
250250
// Slice to the NAV_SECTIONS literal. Outside it sit the docs-scoped metadata
@@ -257,22 +257,25 @@ test('every docs sidebar label and section title is Title Case', async () => {
257257
const nav = layout.slice(start, end);
258258
assert.ok(!nav.includes('generateMetadata'), 'the NAV_SECTIONS slice ran past the end of the literal');
259259

260-
// `label:` is read on its own rather than anchored to a preceding `href:`.
261-
// The anchored form yields NOTHING for an entry written
262-
// `{ label: '...', href: '...' }`, so a key reorder drops that entry from
263-
// the check. The floor below is too coarse to catch it on its own, since it
264-
// only fires once four entries are missing, so the href count is the
265-
// cross-check: every nav item has one of each.
260+
// Two ways an entry can slip out of this check unnoticed, both closed here.
266261
//
267-
// That is not total, and the gap is worth knowing. An entry written with
268-
// DOUBLE quotes on both keys is invisible to both regexes at once, so the
269-
// counts stay equal and this test passes over it. That shape is caught a few
270-
// tests up instead, by 'every doc page on disk is reachable from the
271-
// sidebar', which reads single-quoted hrefs and so reports the page as
272-
// orphaned. Verified: double-quoting one entry reds that test, not this one.
273-
const labels = [...nav.matchAll(/\blabel:\s*'([^']+)'/g)].map((m) => m[1]);
274-
const titles = [...nav.matchAll(/\btitle:\s*'([^']+)'/g)].map((m) => m[1]);
275-
const hrefs = [...nav.matchAll(/\bhref:\s*'([^']+)'/g)].map((m) => m[1]);
262+
// Anchoring `label:` to a preceding `href:` yields NOTHING for an entry
263+
// written `{ label: '...', href: '...' }`, so a key reorder would drop it.
264+
// Each key is therefore read on its own, and the href count is the
265+
// cross-check, since every nav item has one of each.
266+
//
267+
// Matching only single quotes would miss a double-quoted entry, and when
268+
// BOTH its keys are double-quoted the counts stay equal, so the cross-check
269+
// would not notice either. The sibling orphan test covers that for a
270+
// `/docs/*` entry, but NOT for the one `/ui` cross-link, which is not a doc
271+
// directory, so nothing in this file would have caught a sentence-cased
272+
// relabel of it. The quote character is captured and back-referenced instead
273+
// of hard-coded, which reads both styles and lets a label carry the other
274+
// quote inside it.
275+
const quoted = (key) => new RegExp(`\\b${key}:\\s*(['"])(.*?)\\1`, 'g');
276+
const labels = [...nav.matchAll(quoted('label'))].map((m) => m[2]);
277+
const titles = [...nav.matchAll(quoted('title'))].map((m) => m[2]);
278+
const hrefs = [...nav.matchAll(quoted('href'))].map((m) => m[2]);
276279

277280
assert.equal(
278281
labels.length,
@@ -290,7 +293,7 @@ test('every docs sidebar label and section title is Title Case', async () => {
290293
// 'Runtime (Node & Bun)', 'Editor Setup (Neovim, VS Code)', 'cache()'
291294
const word = token.replace(/^\(+|[)(,.]+$/g, '');
292295
if (!/[A-Za-z]/.test(word)) return; // the bare & in 'Streaming & Suspense'
293-
if (IDENTIFIERS.has(word)) return;
296+
if (FIXED_CASING.has(word)) return;
294297
if (i > 0 && MINOR_WORDS.has(word.toLowerCase())) return;
295298
if (!/^[A-Z]/.test(word)) offenders.push(`${value} -> '${word}'`);
296299
});
@@ -304,7 +307,7 @@ test('every docs sidebar label and section title is Title Case', async () => {
304307
'\n\nThe docs sidebar is Title Case throughout, section titles included. Pick the fix that matches the word:\n' +
305308
' 1. ORDINARY WORD: recase it in app/docs/layout.ts. This is the fix nearly every\n' +
306309
' hit wants, and it is what the last two drifts needed.\n' +
307-
' 2. A WORD WHOSE CASING IS NOT PROSE: add it to IDENTIFIERS at the top of\n' +
310+
' 2. A WORD WHOSE CASING IS NOT PROSE: add it to FIXED_CASING at the top of\n' +
308311
' this test, spelled EXACTLY as this message printed it above. Wrapping\n' +
309312
" brackets and trailing punctuation are stripped before the lookup, so a\n" +
310313
" 'cache()' in a label is listed as 'cache'. Two kinds belong there: a code\n" +

0 commit comments

Comments
 (0)