import { cookies } from "next/headers"; // A TEST SERVER'S WAY TO HOLD A STREAMED SECTION BACK (the Inbox, app/page.tsx). // // The home page sends its shell first and the Inbox when its read is done. // Against the e2e fixture that read is over in milliseconds, so a spec could // never see the placeholder, or prove a refresh does not bring it back. A spec // sets this cookie to a number of milliseconds and the Inbox waits that long // before it reads. // // INERT OUTSIDE THE E2E SERVER: without E2E_UMTOOL_STREAM_DELAY=1 (set by // playwright.config.ts on the app server only) the cookie is not even read. export const STREAM_DELAY_COOKIE = "e2e-stream-delay"; const MAX_DELAY_MS = 5_000; export async function e2eStreamDelay(): Promise { if (process.env.E2E_UMTOOL_STREAM_DELAY !== "1") return; const raw = (await cookies()).get(STREAM_DELAY_COOKIE)?.value; const ms = Math.min(Number(raw) || 0, MAX_DELAY_MS); if (ms > 0) await new Promise((resolve) => setTimeout(resolve, ms)); }