๐Ÿ“ฆ cloudflare / vinext

๐Ÿ“„ navigation.spec.ts ยท 72 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72import { test, expect } from "@playwright/test";

const BASE = "http://localhost:4176";

test.describe("Cloudflare Workers Navigation", () => {
  test("navigating between pages via links", async ({ page }) => {
    await page.goto(`${BASE}/`);
    await expect(page.locator("h1")).toHaveText(
      "vinext on Cloudflare Workers",
    );

    // Click About link
    await page.click('a[href="/about"]');
    await expect(page.locator("h1")).toHaveText("About");

    // Click back to home
    await page.click('a[href="/"]');
    await expect(page.locator("h1")).toHaveText(
      "vinext on Cloudflare Workers",
    );
  });

  test("browser back/forward works", async ({ page }) => {
    await page.goto(`${BASE}/`);
    await expect(page.locator("h1")).toHaveText(
      "vinext on Cloudflare Workers",
    );

    await page.click('a[href="/about"]');
    await expect(page.locator("h1")).toHaveText("About");

    await page.goBack();
    await expect(page.locator("h1")).toHaveText(
      "vinext on Cloudflare Workers",
    );

    await page.goForward();
    await expect(page.locator("h1")).toHaveText("About");
  });

  test("RSC endpoint returns flight data for client navigation", async ({
    request,
  }) => {
    // The .rsc URL should return RSC flight payload (not HTML)
    const response = await request.get(`${BASE}/about`, {
      headers: { Accept: "text/x-component" },
    });

    expect(response.status()).toBe(200);
    const body = await response.text();
    // RSC flight payload contains React component references
    // It should NOT be a full HTML document
    expect(body).not.toContain("<!DOCTYPE html>");
    // It should contain some RSC markers (lines starting with digits/hex)
    expect(body.length).toBeGreaterThan(0);
  });

  test("static assets are served (client JS bundle)", async ({ request }) => {
    // First get the home page to find the JS bundle URL
    const html = await (await request.get(`${BASE}/`)).text();
    // The bundle is referenced as import("/assets/index-XXXX.js")
    const match = html.match(/import\("(\/assets\/[^"]+)"\)/);
    expect(match).toBeTruthy();

    const jsUrl = match![1];
    const jsResponse = await request.get(`${BASE}${jsUrl}`);
    expect(jsResponse.status()).toBe(200);
    const contentType = jsResponse.headers()["content-type"];
    expect(contentType).toContain("javascript");
  });
});