cloudflare/vinext

Public

mirrored from https://github.com/cloudflare/vinextAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.0.9

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

tests/e2e/cloudflare-workers/hydration.spec.ts

54lines · modecode

1import { test, expect } from "../fixtures";
2
3const BASE = "http://localhost:4176";
4
5test.describe("Cloudflare Workers Hydration", () => {
6 // The consoleErrors fixture automatically fails tests if any console errors occur.
7 // This catches React hydration mismatches (error #418), runtime errors, etc.
8
9 test("client component hydrates and becomes interactive", async ({
10 page,
11 consoleErrors,
12 }) => {
13 await page.goto(`${BASE}/`);
14
15 // SSR should show initial count
16 await expect(page.locator('[data-testid="count"]')).toHaveText("Count: 0");
17
18 // After hydration, clicking should work
19 await page.click('[data-testid="increment"]');
20 await expect(page.locator('[data-testid="count"]')).toHaveText("Count: 1");
21
22 await page.click('[data-testid="increment"]');
23 await expect(page.locator('[data-testid="count"]')).toHaveText("Count: 2");
24
25 void consoleErrors;
26 });
27
28 test("page with timestamp hydrates without mismatch", async ({
29 page,
30 consoleErrors,
31 }) => {
32 // This test specifically verifies the fix for GitHub issue #61.
33 // The home page has a timestamp that would cause hydration mismatch
34 // if the browser fetched a new RSC payload instead of using embedded data.
35 await page.goto(`${BASE}/`);
36
37 // Wait for the client JS bundle to load and hydrate
38 await page.waitForFunction(
39 () => document.querySelector('[data-testid="increment"]') !== null,
40 );
41
42 // Verify hydration completes and component becomes interactive
43 await page.click('[data-testid="increment"]');
44 await expect(page.locator('[data-testid="count"]')).toHaveText("Count: 1");
45
46 // The timestamp element should exist and have content
47 await expect(page.locator('[data-testid="timestamp"]')).toContainText(
48 "Rendered at:",
49 );
50
51 // consoleErrors fixture will fail this test if any hydration errors occurred
52 void consoleErrors;
53 });
54});
55