")).toBeNull();
});
it("reads the publication date from meta tags", () => {
expect(publishedDate(HTML)).toBe("2026-09-01");
expect(publishedDate("")).toBeNull();
});
});
describe("mainText", () => {
const story = `
${"The developer secured planning permission for a 12MW data center in Bucharest. ".repeat(6)}
`;
it("keeps the largest , drops related / recommended / trending / sidebar / aside / footer blocks and cuts trailing teasers", () => {
const html = `Microsoft expands plans for La Porte campus
`;
const t = mainText(html);
expect(t).toContain("S+B Gruppe to build data center in Bucharest");
expect(t).toContain("planning permission");
for (const leak of ["Microsoft", "Ignis", "More in", "Google", "Equinix", "Vantage", "Digital Realty", "AWS", "Amazon"]) expect(t, leak).not.toContain(leak);
});
it("cutTeasers only cuts after the story has started and only on a heading line", () => {
expect(cutTeasers("Related\nshort lead")).toBe("Related\nshort lead");
const body = "x".repeat(400);
expect(cutTeasers(`${body}\n Tags \n Bucharest\n Comments`)).toBe(body);
expect(cutTeasers(`${body}\nMore in the article follows here with a long sentence about the project itself.`)).toContain("More in the article");
});
});
describe("pdfText limits", () => {
it("rejects oversized PDFs before parsing", async () => {
await expect(pdfText(Buffer.alloc(16 * 1024 * 1024), 60, { maxBytes: 15 * 1024 * 1024 })).rejects.toThrow(/too large/);
});
it("throws on garbage input instead of hanging", async () => {
await expect(pdfText(Buffer.from("%PDF-1.4 definitely not a pdf"), 60, { timeoutMs: 5_000 })).rejects.toThrow();
});
});