11import assert from "node:assert/strict" ;
22import { execFileSync } from "node:child_process" ;
3- import fs from "node:fs" ;
3+ import { mkdtempSync , rmSync , writeFileSync } from "node:fs" ;
4+ import { tmpdir } from "node:os" ;
45import path from "node:path" ;
5- import { lintHyperframeHtml } from "../src/lint/hyperframeLinter" ;
6+ import { fileURLToPath } from "node:url" ;
7+ import { lintHyperframeHtml } from "@hyperframes/lint" ;
68
7- const ROOT = path . resolve ( path . dirname ( new URL ( import . meta. url ) . pathname ) , ".." ) ;
9+ const ROOT = path . resolve ( path . dirname ( fileURLToPath ( import . meta. url ) ) , ".." ) ;
10+ const VALID_COMPOSITION = `
11+ <html>
12+ <body>
13+ <div id="root" data-composition-id="comp-1" data-width="1920" data-height="1080" data-start="0">
14+ <div id="stage"></div>
15+ </div>
16+ <script src="https://cdn.gsap.com/gsap.min.js"></script>
17+ <script>
18+ window.__timelines = window.__timelines || {};
19+ const tl = gsap.timeline({ paused: true });
20+ tl.to("#stage", { opacity: 1, duration: 1 }, 0);
21+ window.__timelines["comp-1"] = tl;
22+ </script>
23+ </body>
24+ </html>` ;
825
9- function testCleanFixturePasses ( ) {
10- const fixturePath = path . join ( ROOT , "src/tests/chat-project-9/index.html" ) ;
11- const html = fs . readFileSync ( fixturePath , "utf8" ) ;
12- const result = lintHyperframeHtml ( html , { filePath : fixturePath } ) ;
26+ async function testCleanFixturePasses ( ) {
27+ const result = await lintHyperframeHtml ( VALID_COMPOSITION , { filePath : "valid.html" } ) ;
1328
14- assert . equal ( result . ok , true , "chat-project-9 should pass without lint errors" ) ;
15- assert . equal ( result . errorCount , 0 , "chat-project-9 should have zero lint errors" ) ;
29+ assert . equal ( result . ok , true , "valid composition should pass without lint errors" ) ;
30+ assert . equal ( result . errorCount , 0 , "valid composition should have zero lint errors" ) ;
1631}
1732
18- function testDetectsMissingCompositionHostId ( ) {
33+ async function testDetectsMissingCompositionHostId ( ) {
1934 const html = `
2035 <html>
2136 <body>
@@ -31,15 +46,15 @@ function testDetectsMissingCompositionHostId() {
3146 </html>
3247 ` ;
3348
34- const result = lintHyperframeHtml ( html ) ;
49+ const result = await lintHyperframeHtml ( html ) ;
3550 const codes = result . findings . map ( ( finding ) => finding . code ) ;
3651
3752 assert . equal ( result . ok , false , "missing composition ids should fail lint" ) ;
3853 assert . ok ( codes . includes ( "root_missing_composition_id" ) ) ;
3954 assert . ok ( codes . includes ( "host_missing_composition_id" ) ) ;
4055}
4156
42- function testDetectsOverlappingGsapTweens ( ) {
57+ async function testDetectsOverlappingGsapTweens ( ) {
4358 const html = `
4459 <html>
4560 <body>
@@ -57,7 +72,7 @@ function testDetectsOverlappingGsapTweens() {
5772 </html>
5873 ` ;
5974
60- const result = lintHyperframeHtml ( html ) ;
75+ const result = await lintHyperframeHtml ( html ) ;
6176 const overlapFinding = result . findings . find (
6277 ( finding ) => finding . code === "overlapping_gsap_tweens" ,
6378 ) ;
@@ -67,29 +82,30 @@ function testDetectsOverlappingGsapTweens() {
6782}
6883
6984function testCliJsonOutput ( ) {
70- const fixturePath = path . join ( ROOT , "src/tests/chat-project-9/index.html" ) ;
71- const tsxBin = path . join ( ROOT , "node_modules/.bin/tsx" ) ;
72- const stdout = execFileSync (
73- tsxBin ,
74- [ "scripts/check-hyperframe-static.ts" , "--json" , fixturePath ] ,
75- {
85+ const tempDir = mkdtempSync ( path . join ( tmpdir ( ) , "hf-core-lint-script-" ) ) ;
86+ try {
87+ const fixturePath = path . join ( tempDir , "index.html" ) ;
88+ writeFileSync ( fixturePath , VALID_COMPOSITION , "utf8" ) ;
89+ const stdout = execFileSync ( "bun" , [ "run" , "check:hyperframe-html" , "--json" , fixturePath ] , {
7690 cwd : ROOT ,
7791 encoding : "utf8" ,
78- } ,
79- ) ;
80- const payload = JSON . parse ( stdout ) ;
92+ } ) ;
93+ const payload = JSON . parse ( stdout ) ;
8194
82- assert . equal ( payload . ok , true ) ;
83- assert . equal ( typeof payload . errorCount , "number" ) ;
84- assert . ok ( Array . isArray ( payload . findings ) ) ;
95+ assert . equal ( payload . ok , true ) ;
96+ assert . equal ( typeof payload . errorCount , "number" ) ;
97+ assert . ok ( Array . isArray ( payload . findings ) ) ;
98+ } finally {
99+ rmSync ( tempDir , { recursive : true , force : true } ) ;
100+ }
85101}
86102
87- function main ( ) {
88- testCleanFixturePasses ( ) ;
89- testDetectsMissingCompositionHostId ( ) ;
90- testDetectsOverlappingGsapTweens ( ) ;
103+ async function main ( ) {
104+ await testCleanFixturePasses ( ) ;
105+ await testDetectsMissingCompositionHostId ( ) ;
106+ await testDetectsOverlappingGsapTweens ( ) ;
91107 testCliJsonOutput ( ) ;
92108 console . log ( "hyperframe linter tests passed" ) ;
93109}
94110
95- main ( ) ;
111+ await main ( ) ;
0 commit comments