/** * Re-record a fixture after a store changes its markup: * npm run record [partNumber] * Writes fixtures//.html, then run `npm test` and fix selectors until green. */ import { mkdirSync, writeFileSync } from "node:fs"; import path from "node:path"; import { getAdapter } from "../src/core/registry.js"; import { normalizeQuery } from "../src/core/normalize.js"; import { PoliteHttp } from "../src/core/politeHttp.js"; const [storeId, rawQuery = "W 712/52"] = process.argv.slice(2); const adapter = storeId ? getAdapter(storeId) : undefined; if (!adapter) { console.error(`Usage: npm run record [partNumber] — unknown store "${storeId ?? ""}"`); process.exit(1); } const q = normalizeQuery(rawQuery); if (!q) { console.error(`Query too short: "${rawQuery}"`); process.exit(1); } const html = await adapter.fetchHtml(q, new PoliteHttp()); const dir = path.join("fixtures", adapter.id); mkdirSync(dir, { recursive: true }); const file = path.join(dir, `${q.canonical}.${adapter.fixtureExt ?? "html"}`); writeFileSync(file, html); const offers = adapter.parse(html, q); console.log(`Recorded ${file} (${html.length} bytes); current selectors parse ${offers.length} offer(s).`);