Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions skills/renderdiff/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,10 @@ computed: 2 findings; dom identical on 2 of 3 route(s), differs /pricing (1), so
`side` to make the sides look alike, hiding or removing an element on one side. `side` is for
markup that legitimately differs. Say in the verdict that a hook ran (`hook: true`).
- **Signed-in pages:** `npx playwright codegen --save-storage=auth.json <login url>`, then
`--storage-state auth.json` (or `--left-`/`--right-storage-state`, or config `storageState`,
relative to the config file). The file holds live session tokens: never commit or paste it,
add it to `.gitignore`. The out dir then holds signed-in screenshots and text: keep it out of
git too.
`--storage-state auth.json` (or `--left-storage-state`/`--right-storage-state`, or config
`storageState`, relative to the config file). The file holds live session tokens: never
commit or paste it, add it to `.gitignore`. The out dir then holds signed-in screenshots and
text: keep it out of git too.

## Config file

Expand Down
15 changes: 15 additions & 0 deletions tests/helpers/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,18 @@ export function card(report: Report, route: string, width: number): ReportCard {
}
return found;
}

/** The flags `--help` lists under Options, from each entry's first column. */
export function helpOptions(help: string): string[] {
const section = help.slice(help.indexOf("\n Options\n"), help.indexOf("\n Default widths"));
return section
.split("\n")
.filter((l) => /^ {4}-/.test(l))
.flatMap(
(l) =>
l
.trim()
.split(/ {2,}/)[0]!
.match(/--[a-z][a-z-]*/g) ?? [],
);
}
81 changes: 48 additions & 33 deletions tests/unit/cli-args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import fs from "node:fs";
import path from "node:path";
import { after, describe, test } from "node:test";
import { cleanupTempDirs, runCli, REPO_ROOT, tempDir } from "../helpers/cli.ts";
import { helpOptions } from "../helpers/parse.ts";

after(cleanupTempDirs);

Expand All @@ -33,39 +34,53 @@ async function rejects(args: string[], needle: string) {
}

describe("help and version", () => {
test("--help exits 0 and documents every flag", async () => {
const r = await runCli(["--help"], { noOut: true });
assert.equal(r.code, 0);
for (const flag of [
"--left",
"--right",
"--width",
"--threshold",
"--out",
"--concurrency",
"--config",
"--dry-run",
"--open",
"--progress",
"--no-progress",
"--selector",
"--left-selector",
"--right-selector",
"--storage-state",
"--left-storage-state",
"--right-storage-state",
"--accept",
"--rerun-failed",
"--computed",
"--mask",
"--mask-media",
"--no-freeze-video",
"--no-recheck",
"--sitemap",
]) {
assert.ok(r.stdout.includes(flag), `--help does not mention ${flag}`);
}
assert.equal(r.stderr, "");
test("the parser, --help and the docs name the same flags", async () => {
const help = await runCli(["--help"], { noOut: true });
assert.equal(help.code, 0);
assert.equal(help.stderr, "");
const flags = (s: string) => new Set(s.match(/--[a-z][a-z-]+/g));
const read = (f: string) => fs.readFileSync(path.join(REPO_ROOT, f), "utf8");
const md = (dir: string) =>
fs
.readdirSync(path.join(REPO_ROOT, dir), { recursive: true, encoding: "utf8" })
.filter((f) => f.endsWith(".md"))
.map((f) => path.join(dir, f));
const known = flags(help.stdout);
const options = helpOptions(help.stdout);

// Read as text: the parser has no flag list to import.
const parsed = new Set(
[...read("src/cli.ts").matchAll(/v === "(--[a-z-]+)"/g)].map((m) => m[1]!),
);
const problems = [
...[...parsed]
.filter((f) => !known.has(f))
.map((f) => `the parser takes ${f}, --help doesn't name it`),
...options
.filter((f) => !parsed.has(f))
.map((f) => `--help lists ${f}, the parser doesn't take it`),
];

const readme = read("README.md");
const table = readme.slice(readme.indexOf("| Argument or flag"));
const column = table
.slice(0, table.indexOf("\n\n"))
.split("\n")
.map((row) => row.split("|")[1])
.join(" ");
const documented = flags(column);
for (const f of options)
if (!documented.has(f)) problems.push(`--help lists ${f}, the README table doesn't`);
for (const f of documented)
if (!options.includes(f))
problems.push(`the README table lists ${f}, --help's Options don't`);

const foreign = new Set(["--immutable"]); // yarn install, in docs/case-study.md
for (const f of ["README.md", ...md("docs"), ...md("skills")])
for (const flag of flags(read(f)))
if (!known.has(flag) && !foreign.has(flag))
problems.push(`${f} names ${flag}, which --help doesn't`);
assert.deepEqual(problems, []);
});

test("-h is the same as --help", async () => {
Expand Down
Loading