// author: simon-pierre boucher import { readFileSync } from "node:fs"; import { fileURLToPath } from "node:url"; import { dirname, resolve } from "node:path"; import { describe, expect, it } from "vitest"; import { extract } from "./pipeline.js"; const here = dirname(fileURLToPath(import.meta.url)); const fixture = (name: string): string => readFileSync(resolve(here, "../../../test/fixtures/html", name), "utf8"); describe("fixture: shopify-product", () => { const html = fixture("shopify-product.html"); const r = extract(html, { url: "https://gardenco.example/products/trellis-frame", onlyMainContent: false }); if (!r.ok) throw new Error("extraction failed"); const d = r.value; it("harvests the Product JSON-LD without a model", () => { const product = d.structured.jsonld.find( (n): n is Record => typeof n === "object" && n !== null && (n as Record)["@type"] === "Product", ); expect(product?.["sku"]).toBe("TRL-2026"); const offers = product?.["offers"] as Record | undefined; expect(offers?.["price"]).toBe("49.00"); }); it("prefers canonical and OpenGraph metadata", () => { expect(d.metadata.canonical).toBe("https://gardenco.example/products/trellis-frame"); expect(d.metadata.title).toBe("Trellis Climbing Frame"); expect(d.metadata.siteName).toBe("GardenCo"); }); it("renders the spec table as a GFM table", () => { expect(d.markdown).toContain("| Spec | Value |"); expect(d.markdown).toContain("| Material | Powder-coated steel |"); }); it("resolves lazy data-src images to absolute URLs", () => { expect(d.html).toContain("https://gardenco.example/img/trellis-800.jpg"); }); it("absolutizes and classifies links", () => { const reviews = d.links.find((l) => l.url.includes("/reviews")); expect(reviews?.url).toBe("https://gardenco.example/products/trellis-frame/reviews"); expect(reviews?.isInternal).toBe(true); }); });