import fs from "node:fs"; import path from "node:path"; import { test, expect } from "@playwright/test"; import { FIXTURE_SITES, FIXTURE_SUMMARY_NAME, FIXTURE_UNLISTED_SITE, buildFixtureInputs, buildFixtureSummary, } from "./fixture-summary"; // Release 14 slice HS: a site with site.json `listed: false` builds and // deploys, and the homepage lists it nowhere — not a card, not a chart series, // not a recent item — and counts the channels only it exposes in no total. // // The fixture summary (fixture-summary.ts) is built over six listed sites and // one unlisted one, which has two channels of its own and shares the first // site's first channel. const NEEDLES = [FIXTURE_UNLISTED_SITE.siteId, FIXTURE_UNLISTED_SITE.siteTitle]; test("the summary the server reads is the one built without the unlisted site", () => { // The site is in the builder's input: unlisted, with recordings of its own // and a channel shared with the first listed site. const { stats, channelSites, sites } = buildFixtureInputs(); const unlisted = sites.find((s) => s.siteId === FIXTURE_UNLISTED_SITE.siteId); expect(unlisted?.listed).toBe(false); const own = stats.filter((s) => s.channelSlug.startsWith(`${FIXTURE_UNLISTED_SITE.siteId}-ch`)); expect(own.length).toBeGreaterThan(0); expect(channelSites[`${FIXTURE_SITES[0].siteId}-ch1`]).toContain(FIXTURE_UNLISTED_SITE.siteId); // Listed, the same site would change the summary: a card, and its recordings. const withoutIt = buildFixtureSummary(FIXTURE_SITES, []); const asListed = buildFixtureSummary([...FIXTURE_SITES, FIXTURE_UNLISTED_SITE], []); expect(asListed.sites.map((s) => s.siteId)).toContain(FIXTURE_UNLISTED_SITE.siteId); expect(asListed.totals.transcripts).toBe(withoutIt.totals.transcripts + own.length); const onDisk = JSON.parse( fs.readFileSync(path.resolve(process.cwd(), "e2e", FIXTURE_SUMMARY_NAME), "utf8"), ); // Every array and every total: what the six listed sites alone produce. expect(onDisk).toEqual(JSON.parse(JSON.stringify(withoutIt))); const text = JSON.stringify(onDisk); for (const needle of NEEDLES) expect(text).not.toContain(needle); expect(onDisk.sites.map((s: { siteId: string }) => s.siteId)).toEqual( FIXTURE_SITES.map((s) => s.siteId), ); }); for (const route of ["/", "/stats/"]) { test(`${route} names no unlisted site, in its HTML or on the page`, async ({ page }) => { const res = await page.goto(route); expect(res?.ok()).toBe(true); const served = (await res?.text()) ?? ""; // The listed sites are there, so the check below is not vacuous. for (const s of FIXTURE_SITES) expect(served).toContain(s.siteId); for (const needle of NEEDLES) { expect(served).not.toContain(needle); expect(await page.content()).not.toContain(needle); } }); }