Skip to content

Commit d62bc0c

Browse files
test(cli): serve the video-alpha fixtures from memory, not request paths
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 1034db9 commit d62bc0c

1 file changed

Lines changed: 3 additions & 9 deletions

File tree

‎packages/cli/src/commands/layout-audit.video-alpha.chromium.test.ts‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,6 @@ function page(video: string, words: string): string {
7878
const videoTag = (src: string, extra = "") =>
7979
`<video id="clip" src="/${src}" muted playsinline ${extra} style="position:absolute;left:0;top:0;width:640px;height:360px;z-index:2"></video>`;
8080

81-
function readClip(dir: string, path: string): Buffer | null {
82-
try {
83-
return readFileSync(join(dir, path.slice(1)));
84-
} catch {
85-
return null;
86-
}
87-
}
88-
8981
// Chromium only seeks a media resource its server serves by byte range.
9082
function serveByteRange(body: Buffer, rangeHeader: string | undefined, response: ServerResponse) {
9183
const range = /bytes=(\d+)-(\d*)/.exec(rangeHeader ?? "");
@@ -106,6 +98,7 @@ describe.runIf(executablePath && hasFfmpeg)("text_occluded behind a <video> in C
10698
let origin: string;
10799
let clipDir: string;
108100
const pages = new Map<string, string>();
101+
const clips = new Map<string, Buffer>();
109102

110103
beforeAll(async () => {
111104
clipDir = mkdtempSync(join(tmpdir(), "hf-video-alpha-"));
@@ -118,6 +111,7 @@ describe.runIf(executablePath && hasFfmpeg)("text_occluded behind a <video> in C
118111
join(clipDir, name),
119112
]);
120113
if (result.status !== 0) throw new Error(`ffmpeg ${name}: ${result.stderr}`);
114+
clips.set(`/${name}`, readFileSync(join(clipDir, name)));
121115
}
122116
server = createServer((request, response) => {
123117
const path = (request.url ?? "/").split("?")[0] ?? "/";
@@ -127,7 +121,7 @@ describe.runIf(executablePath && hasFfmpeg)("text_occluded behind a <video> in C
127121
response.end(html);
128122
return;
129123
}
130-
const body = readClip(clipDir, path);
124+
const body = clips.get(path);
131125
if (body) serveByteRange(body, request.headers.range, response);
132126
else response.writeHead(404).end();
133127
});

0 commit comments

Comments
 (0)