/**
* End-to-end checks for dynamic sites against a running dev server.
*
* SITES_E2E_URL=http://localhost:3100 SITES_DOMAIN=gitforstatic.localhost bun run e2e/sites.e2e.ts
*
* Requests to site hosts go to the forge's address with an explicit Host header, so no hosts-file entries are needed.
*/
import { deployScratch, DOMAIN, FORGE, HTTP_OK, log, send } from "./helpers";
const BLOCKED_STATUS = 599;
const HTTP_ACCEPTED = 202;
const HTTP_UNAUTHORIZED = 401;
const HTTP_NOT_FOUND = 404;
let failures = 0;
function check(name: string, ok: boolean, detail = ""): void {
log(`${ok ? "ok " : "FAIL"} ${name}${ok || !detail ? "" : ` -- ${detail}`}`);
if (!ok) failures += 1;
}
const first = await deployScratch("site-a");
check("scratch deploy returns a claim token", first.claimToken.startsWith("gitfor_claim_"));
const second = await deployScratch("site-b");
check(
"each scratch site gets its own origin",
first.host !== second.host && first.host.endsWith(`--scratch.${DOMAIN}`),
);
const page = await send(first.host, "/");
check(
"static assets are served through env.ASSETS",
page.status === HTTP_OK && page.body.includes("site-a"),
page.body,
);
check(
"worker source is never served statically",
(await send(first.host, "/_worker.js")).body.includes("export default") === false,
);
const forgeCookie =