| 1 | import * as Playwright from "@alchemy.run/cloudflare-test-tools/e2e/Playwright"; |
| 2 | import { expect, test } from "@playwright/test"; |
| 3 | |
| 4 | for (const mode of Playwright.SERVER_METHODS) { |
| 5 | test.describe(mode, () => { |
| 6 | const it = Playwright.make(mode); |
| 7 | |
| 8 | it("SSRs the homepage with the docs sidebar", async ({ page, server }) => { |
| 9 | const response = await page.goto(server.url.toString()); |
| 10 | expect(response?.status()).toBe(200); |
| 11 | await expect( |
| 12 | page.getByRole("heading", { name: "Vocs Fixture Home" }), |
| 13 | ).toBeVisible(); |
| 14 | await expect(page.getByTestId("home-marker")).toHaveText("HOME_MARKER"); |
| 15 | // The docs shell (sidebar) is rendered by the worker at request time. |
| 16 | const sidebar = page.getByRole("complementary"); |
| 17 | await expect(sidebar.getByRole("link", { name: "Guide" })).toBeVisible(); |
| 18 | await expect( |
| 19 | sidebar.getByRole("link", { name: "Counter" }), |
| 20 | ).toBeVisible(); |
| 21 | }); |
| 22 | |
| 23 | it("navigates to a second page from the sidebar", async ({ |
| 24 | page, |
| 25 | server, |
| 26 | }) => { |
| 27 | await page.goto(server.url.toString()); |
| 28 | await page |
| 29 | .getByRole("complementary") |
| 30 | .getByRole("link", { name: "Guide" }) |
| 31 | .click(); |
| 32 | await page.waitForURL("**/guide"); |
| 33 | await expect(page.getByTestId("guide-marker")).toHaveText("GUIDE_MARKER"); |
| 34 | }); |
| 35 | |
| 36 | it("hydrates the custom MDX React component", async ({ page, server }) => { |
| 37 | await page.goto(new URL("/counter", server.url).toString()); |
| 38 | await expect(page.getByTestId("counter-page-marker")).toHaveText( |
| 39 | "COUNTER_PAGE_MARKER", |
| 40 | ); |
| 41 | const counter = page.getByTestId("counter"); |
| 42 | await expect(counter).toHaveText("count: 0"); |
| 43 | // The first click can land before hydration attaches the listener; |
| 44 | // retry until the click observably increments. |
| 45 | await expect(async () => { |
| 46 | await counter.click(); |
| 47 | await expect(counter).toHaveText(/count: [1-9]\d*/, { timeout: 500 }); |
| 48 | }).toPass(); |
| 49 | }); |
| 50 | |
| 51 | it("serves the static asset", async ({ server }) => { |
| 52 | const response = await server.fetch("/hello.txt"); |
| 53 | expect(response.status).toBe(200); |
| 54 | expect(await response.text()).toContain("hello from public/"); |
| 55 | }); |
| 56 | }); |
| 57 | } |
| 58 | |
| 59 | // Build-time artifacts only exist in the production build: vocs prerenders |
| 60 | // llms.txt / llms-full.txt into dist/public, served by the assets layer. |
| 61 | test.describe("live artifacts", () => { |
| 62 | const it = Playwright.make("live"); |
| 63 | |
| 64 | it("serves the generated llms.txt from assets", async ({ server }) => { |
| 65 | const response = await server.fetch("/llms.txt"); |
| 66 | expect(response.status).toBe(200); |
| 67 | }); |
| 68 | }); |