fix(check): mark a contrast finding by its severity and quote its text (#7752)

The Contrast section printed every finding with the error mark, so a
failure seen at a single sample (a warning) read as "✗ ... 0 error(s),
1 warning(s)". It now uses the same severity icon as the other sections.

A finding on an element without an id is named by an nth-of-type path,
which does not say which text failed. The line now quotes the text the
audit judged, as `validate` already does.

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
wonjang
2026-11-16 18:15:53 +00:00
committed by GitHub
co-authored by Claude Fable 5.2
parent 42508c1ef1
commit ec5a4e2a10
2 changed files with 46 additions and 1 deletions
+44
View File
@@ -2009,6 +2009,50 @@ describe("check pipeline", () => {
expect(said).not.toContain("Browser session never ran");
});
it("marks a contrast finding by its severity and quotes the text it judged", async () => {
const finding = (severity: "error" | "warning", text: string): CheckContrastFinding => ({
...checkFindingOf("contrast_aa_failure", severity, { x: 0, y: 0, width: 10, height: 10 }),
selector: "div > div:nth-of-type(35) > div:nth-of-type(3)",
text,
fg: "rgb(110,110,110)",
bg: "rgb(30,30,30)",
ratio: 2.39,
requiredRatio: 3,
suggestedColor: "rgb(219,108,80)",
large: true,
});
const report = reportWithFindings({
contrast: {
...emptySection([
finding("warning", "passing through"),
finding("error", "held on screen"),
]),
errorCount: 1,
warningCount: 1,
enabled: true,
samples: [1],
checked: 2,
passed: 0,
},
});
const log = vi.spyOn(console, "log").mockImplementation(() => undefined);
const command = createCheckCommand({
resolveProject: () => PROJECT,
runPipeline: vi.fn(async () => report),
prepareMedia: vi.fn(async () => []),
withMeta: (value) => value,
});
await runViaCli(command, { rawArgs: [] });
const lines = log.mock.calls.map((call) => String(call[0]));
const lineOf = (text: string) => lines.find((line) => line.includes(`"${text}"`)) ?? "";
expect(lineOf("passing through")).toContain("⚠");
expect(lineOf("passing through")).not.toContain("✗");
expect(lineOf("held on screen")).toContain("✗");
expect(lineOf("held on screen")).toContain("2.39:1 (need 3:1");
});
describe("remembers the newest check for hyperframes feedback", () => {
const run = (runPipeline: () => Promise<CheckReport>) =>
runViaCli(
+2 -1
View File
@@ -855,8 +855,9 @@ function printContrastSection(report: CheckReport): void {
return;
}
for (const finding of section.findings) {
const text = finding.text ? ` ${c.dim(`"${terminalText(finding.text)}"`)}` : "";
console.log(
` ${c.error("✗")} ${terminalText(finding.selector)} ${finding.ratio}:1 (need ${finding.requiredRatio}:1, ${formatFindingTimes(finding)})`,
` ${findingIcon(finding)} ${terminalText(finding.selector)}${text} ${finding.ratio}:1 (need ${finding.requiredRatio}:1, ${formatFindingTimes(finding)})`,
);
const source = `Try ${terminalText(finding.suggestedColor)}; source ${terminalText(finding.sourceFile)}`;
console.log(` ${c.dim(source)}`);