import fs from "node:fs"; import path from "node:path"; // A FIXTURE ARTICLE PUBLISH for /articles/ and /m/ (release 26 A3). The pages // read the directory E2E_ARTICLES_PUBLIC_DIR names instead of public/ while it // holds articles/index.json (app/lib/articles.ts, honoured only outside a // production build), so a spec shows them with articles whatever this checkout // has composed. e2e/articles.spec.ts writes it and removes it after: with it // gone, /articles/ is the honest empty index again (no-data and marketing read // that). playwright.config.ts clears it before the server starts. // // Its data is export's report-site fixture (export/fixtures/report-site/ // public: the view JSON compose writes), as compose writes it for the homepage: // under /articles/ rather than a site's /pages/, and one moment opening in the listed // public archive that publishes its channel (an absolute corpusUrl) — the // others in none. The binary media is not copied: nothing here is served. export const FIXTURE_ARTICLES_NAME = ".e2e-articles"; export const FIXTURE_ARTICLE_ID = "demo-factcheck"; export const FIXTURE_ARCHIVE_URL = "https://archive.example.test"; export const FIXTURE_LINKED_MOMENT = "demo-channel/abc123/3126.00-3151.00"; // Resolved from the cwd, as playwright.config.ts resolves the fixtures: the suite runs in homepage/. const SOURCE = path.resolve(process.cwd(), "..", "export", "fixtures", "report-site", "public"); function copyJson(from: string, to: string, edit?: (v: Record) => void): void { const text = fs.readFileSync(from, "utf8").replaceAll('"/pages/', '"/articles/'); const value = JSON.parse(text) as Record; edit?.(value); fs.mkdirSync(path.dirname(to), { recursive: true }); fs.writeFileSync(to, JSON.stringify(value, null, 2)); } function walk(dir: string, rel = ""): string[] { const out: string[] = []; for (const e of fs.readdirSync(dir, { withFileTypes: true })) { const r = rel ? `${rel}/${e.name}` : e.name; if (e.isDirectory()) out.push(...walk(path.join(dir, e.name), r)); else if (e.name.endsWith(".json")) out.push(r); } return out; } export function writeFixtureArticles(dest: string): void { clearFixtureArticles(dest); for (const rel of walk(path.join(SOURCE, "pages"))) { copyJson(path.join(SOURCE, "pages", rel), path.join(dest, "articles", rel)); } for (const rel of walk(path.join(SOURCE, "m"))) { copyJson(path.join(SOURCE, "m", rel), path.join(dest, "m", rel), (v) => { if (rel === `${FIXTURE_LINKED_MOMENT}/moment.json`) { const record = v.record as Record; record.corpusUrl = `${FIXTURE_ARCHIVE_URL}/?v=demo-channel%2Fabc123&t=3126`; } }); } } export function clearFixtureArticles(dest: string): void { fs.rmSync(dest, { recursive: true, force: true }); }