Files
hyperframes/packages/cli/src/capture/tokenExtractor.test.ts
T
Miguel Ángel 0d6bdd453b fix(cli): capture writes inline SVG logos whole and parakeet takes long audio (#5662)
* fix(cli): capture writes inline SVG logos whole and parakeet takes long audio

* fix(cli): keep the decode timeout comment under the line limit
2026-10-15 21:16:20 +00:00

38 lines
1.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { runInNewContext } from "node:vm";
import { Window } from "happy-dom";
import type { Page } from "puppeteer-core";
import { extractTokens } from "./tokenExtractor.js";
async function tokensOf(body: string) {
const window = new Window();
window.document.body.innerHTML = body;
const evaluate: Page["evaluate"] = async (script, ..._args) => {
if (typeof script !== "string") throw new Error("Expected a page expression");
return runInNewContext(script, {
window,
document: window.document,
location: window.location,
getComputedStyle: window.getComputedStyle.bind(window),
});
};
try {
return await extractTokens({ evaluate } as Page);
} finally {
await window.happyDOM.close();
}
}
describe("capture tokens", () => {
it("keeps an inline SVG logo over 10 KB whole", async () => {
const shapes = Array.from({ length: 3000 }, (_, i) => `<path d="M${i} 0h1v10h-1z"></path>`);
const logo = `<svg viewBox="0 0 3000 10" width="300">${shapes.join("")}</svg>`;
expect(logo.length).toBeGreaterThan(10_000);
const tokens = await tokensOf(`<header class="logo"><a href="/">${logo}</a></header>`);
expect(tokens.svgs).toHaveLength(1);
expect(tokens.svgs[0]!.outerHTML.length).toBe(logo.length);
expect(tokens.svgs[0]!.outerHTML.endsWith("</svg>")).toBe(true);
expect(tokens.svgs[0]!.isLogo).toBe(true);
});
});