fix(cli): read effective text fill by property, not getPropertyValue

The layout-audit test mock returns computed styles as plain camelCase
properties (no getPropertyValue), so the invisible-text detector threw
'cs.getPropertyValue is not a function' and broke the whole audit in CI. Read
webkitTextFillColor/webkitBackgroundClip/backgroundClip by property to match
the rest of the script (works in a real browser too). Adds tests: flags
transparent -webkit-text-fill-color, ignores opaque color, ignores gradient
text (background-clip:text).
This commit is contained in:
Vance Ingalls
2026-07-11 17:00:40 -07:00
parent 9ae84c652c
commit a8fd8562a8
2 changed files with 55 additions and 5 deletions
@@ -812,12 +812,12 @@
const text = textContentFor(element);
if (!text) return null;
const cs = getComputedStyle(element);
const fill = cs.getPropertyValue("-webkit-text-fill-color") || cs.color;
// Vendor computed-style props are read by property (camelCase), matching
// the rest of this script; `webkitTextFillColor` computes to `color` when
// unset, so it is the effective fill directly.
const fill = cs.webkitTextFillColor || cs.color;
if (colorAlpha(fill) > 0.05) return null;
const clip =
cs.getPropertyValue("-webkit-background-clip") ||
cs.getPropertyValue("background-clip") ||
"";
const clip = cs.webkitBackgroundClip || cs.backgroundClip || "";
if (/text/i.test(clip)) return null;
return {
code: "text_not_painted",
@@ -346,6 +346,56 @@ it("uses the bridge opacity floor across the ancestor chain", () => {
expect(candidates.some((candidate) => candidate.selector === "#stacked-copy")).toBe(true);
});
describe("layout-audit.browser invisible text", () => {
afterEach(() => {
vi.restoreAllMocks();
document.body.innerHTML = "";
delete (window as unknown as { __hyperframesLayoutAudit?: unknown }).__hyperframesLayoutAudit;
clearGeometryCollector();
});
function invisibleTextScene(headlineStyle: Partial<CSSStyleDeclaration>): AuditIssue[] {
document.body.innerHTML = `
<div id="root" data-composition-id="main" data-width="640" data-height="360">
<div id="headline">Headline copy</div>
</div>
`;
installGeometry(
{
root: rect({ left: 0, top: 0, width: 640, height: 360 }),
headline: rect({ left: 40, top: 150, width: 300, height: 56 }),
text: rect({ left: 40, top: 150, width: 300, height: 56 }),
},
{ headline: headlineStyle },
);
installAuditScript();
return runAudit();
}
it("flags text whose -webkit-text-fill-color is transparent", () => {
const issues = invisibleTextScene({
color: "rgb(255, 255, 255)",
webkitTextFillColor: "rgba(0, 0, 0, 0)",
} as unknown as Partial<CSSStyleDeclaration>);
const invisible = issues.find((issue) => issue.code === "text_not_painted");
expect(invisible).toMatchObject({ selector: "#headline", severity: "error" });
});
it("does not flag text with an opaque color and default fill", () => {
const issues = invisibleTextScene({ color: "rgb(255, 255, 255)" });
expect(issues.some((issue) => issue.code === "text_not_painted")).toBe(false);
});
it("does not flag gradient text (transparent fill clipped to the glyphs)", () => {
const issues = invisibleTextScene({
color: "rgb(255, 255, 255)",
webkitTextFillColor: "rgba(0, 0, 0, 0)",
webkitBackgroundClip: "text",
} as unknown as Partial<CSSStyleDeclaration>);
expect(issues.some((issue) => issue.code === "text_not_painted")).toBe(false);
});
});
describe("layout-audit.browser content overlap", () => {
afterEach(() => {
vi.restoreAllMocks();