From 2213e9f7a461b17eb6d01bd84a8dbd258e80c2f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Wed, 1 Apr 2026 18:30:13 +0200 Subject: [PATCH] refactor(lint): split monolithic test file into per-rule-module test files (#181) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary - Splits the 872-line `hyperframeLinter.test.ts` into focused per-domain test files matching the rule module structure from #170 - Tests still use the public API (`lintHyperframeHtml`) — no internals exposed - Fixes misplaced tests: `gsap_css_transform_conflict` tests were inside `describe("lintScriptUrls")`, caption/adapter tests were inside `describe("template_literal_selector rule")` ## New structure ``` src/lint/ hyperframeLinter.test.ts — orchestrator integration + lintScriptUrls (8 tests) rules/ core.test.ts — root attrs, timeline registry, host id (6 tests) media.test.ts — duplicate ids, missing id/src, preload (6 tests) gsap.test.ts — clip element, transform conflict, missing script (12 tests) captions.test.ts — caption exit, overflow, relative position (5 tests) composition.test.ts — external script, template literal selector (5 tests) adapters.test.ts — missing Lottie/Three.js scripts (8 tests) ``` ## Test plan - [x] 404 tests pass (402 before — 2 extra from previously misplaced adapter tests now correctly counted) - [x] Lint + format clean --- .../core/src/lint/hyperframeLinter.test.ts | 744 +----------------- packages/core/src/lint/rules/adapters.test.ts | 143 ++++ packages/core/src/lint/rules/captions.test.ts | 124 +++ .../core/src/lint/rules/composition.test.ts | 97 +++ packages/core/src/lint/rules/core.test.ts | 94 +++ packages/core/src/lint/rules/gsap.test.ts | 257 ++++++ packages/core/src/lint/rules/media.test.ts | 92 +++ 7 files changed, 808 insertions(+), 743 deletions(-) create mode 100644 packages/core/src/lint/rules/adapters.test.ts create mode 100644 packages/core/src/lint/rules/captions.test.ts create mode 100644 packages/core/src/lint/rules/composition.test.ts create mode 100644 packages/core/src/lint/rules/core.test.ts create mode 100644 packages/core/src/lint/rules/gsap.test.ts create mode 100644 packages/core/src/lint/rules/media.test.ts diff --git a/packages/core/src/lint/hyperframeLinter.test.ts b/packages/core/src/lint/hyperframeLinter.test.ts index e8dbaf35d..7285dca30 100644 --- a/packages/core/src/lint/hyperframeLinter.test.ts +++ b/packages/core/src/lint/hyperframeLinter.test.ts @@ -1,7 +1,7 @@ import { describe, it, expect, vi } from "vitest"; import { lintHyperframeHtml, lintScriptUrls } from "./hyperframeLinter.js"; -describe("lintHyperframeHtml", () => { +describe("lintHyperframeHtml — orchestrator", () => { const validComposition = ` @@ -24,72 +24,6 @@ describe("lintHyperframeHtml", () => { expect(result.errorCount).toBe(0); }); - it("reports error when root is missing data-composition-id", () => { - const html = ` - -
- -`; - const result = lintHyperframeHtml(html); - const finding = result.findings.find((f) => f.code === "root_missing_composition_id"); - expect(finding).toBeDefined(); - expect(finding?.severity).toBe("error"); - }); - - it("reports error when root is missing data-width or data-height", () => { - const html = ` - -
- -`; - const result = lintHyperframeHtml(html); - const finding = result.findings.find((f) => f.code === "root_missing_dimensions"); - expect(finding).toBeDefined(); - expect(finding?.severity).toBe("error"); - }); - - it("reports error when timeline registry is missing", () => { - const html = ` - -
- -`; - const result = lintHyperframeHtml(html); - const finding = result.findings.find((f) => f.code === "missing_timeline_registry"); - expect(finding).toBeDefined(); - }); - - it("reports error for duplicate media ids", () => { - const html = ` - -
- - -
- -`; - const result = lintHyperframeHtml(html); - const finding = result.findings.find((f) => f.code === "duplicate_media_id"); - expect(finding).toBeDefined(); - expect(finding?.severity).toBe("error"); - expect(finding?.elementId).toBe("v1"); - }); - - it("reports error for composition host missing data-composition-id", () => { - const html = ` - -
-
-
- -`; - const result = lintHyperframeHtml(html); - const finding = result.findings.find((f) => f.code === "host_missing_composition_id"); - expect(finding).toBeDefined(); - }); - it("attaches filePath to findings when option is set", () => { const html = "
"; const result = lintHyperframeHtml(html, { filePath: "test.html" }); @@ -99,7 +33,6 @@ describe("lintHyperframeHtml", () => { }); it("deduplicates identical findings", () => { - // Calling with the same HTML should not produce duplicate entries const html = `
@@ -111,44 +44,6 @@ describe("lintHyperframeHtml", () => { expect(codes.length).toBe(uniqueCodes.length); }); - it("reports info for composition with external CDN script dependency", () => { - const html = ``; - const result = lintHyperframeHtml(html, { filePath: "compositions/rockets.html" }); - const finding = result.findings.find( - (f) => f.code === "external_script_dependency" && f.message.includes("cdnjs.cloudflare.com"), - ); - expect(finding).toBeDefined(); - expect(finding?.severity).toBe("info"); - // info findings do not count as errors — ok should still be true - expect(result.ok).toBe(true); - expect(result.errorCount).toBe(0); - }); - - it("does not report external_script_dependency for inline scripts", () => { - const html = ` - -
- -
-`; - const result = lintHyperframeHtml(html); - expect(result.findings.find((f) => f.code === "external_script_dependency")).toBeUndefined(); - }); - it("strips