-
-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathrender-type.spec.ts
107 lines (95 loc) · 3.81 KB
/
render-type.spec.ts
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { expect } from '@playwright/test';
import { test, prepareNormalSetup } from './utils.js';
const startApp = prepareNormalSetup('render-type');
test.describe('render type', () => {
test.skip(
({ browserName }) => browserName !== 'chromium',
'Browsers are not relevant for this test. One is enough.',
);
test.describe('static', () => {
let port: number;
let stopApp: () => Promise<void>;
test.beforeAll(async () => {
({ port, stopApp } = await startApp('STATIC'));
});
test.afterAll(async () => {
await stopApp();
});
test('renders static content', async ({ page }) => {
await page.goto(`http://localhost:${port}/server/static/static-echo`);
expect(await page.getByTestId('echo').innerText()).toEqual('static-echo');
});
test('does not hydrate server components', async ({ page }) => {
await page.goto(`http://localhost:${port}/server/static/static-echo`);
const timestamp = await page.getByTestId('timestamp').innerText();
await page.waitForTimeout(100);
await page.reload();
// Timestamp should remain the same, because its build time.
expect(await page.getByTestId('timestamp').innerText()).toEqual(
timestamp,
);
await page.waitForTimeout(100);
});
test('hydrates client components', async ({ page }) => {
await page.goto(`http://localhost:${port}/client/static/static-echo`);
expect(await page.getByTestId('echo').innerText()).toEqual('static-echo');
const timestamp = await page.getByTestId('timestamp').innerText();
await page.waitForTimeout(100);
await page.reload();
// Timestamp should update with each refresh, because its client rendered.
expect(await page.getByTestId('timestamp').innerText()).not.toEqual(
timestamp,
);
await page.waitForTimeout(100);
// Timestamp should update in the browser because its hydrated.
expect(await page.getByTestId('timestamp').innerText()).not.toEqual(
timestamp,
);
});
});
test.describe('dynamic', () => {
let port: number;
let stopApp: () => Promise<void>;
test.beforeAll(async () => {
({ port, stopApp } = await startApp('PRD'));
});
test.afterAll(async () => {
await stopApp();
});
test('renders dynamic content', async ({ page }) => {
await page.goto(`http://localhost:${port}/server/dynamic/dynamic-echo`);
expect(await page.getByTestId('echo').innerText()).toEqual(
'dynamic-echo',
);
});
test('does not hydrate server components', async ({ page }) => {
await page.goto(`http://localhost:${port}/server/dynamic/dynamic-echo`);
const timestamp = await page.getByTestId('timestamp').innerText();
await page.waitForTimeout(100);
await page.reload();
// Timestamp should update with each refresh, because its server rendered.
expect(await page.getByTestId('timestamp').innerText()).not.toBe(
timestamp,
);
});
test('hydrates client components', async ({ page }) => {
await page.goto(`http://localhost:${port}/client/dynamic/dynamic-echo`);
expect(await page.getByTestId('echo').innerText()).toEqual(
'dynamic-echo',
);
const timestamp = await page.getByTestId('timestamp').innerText();
await page.waitForTimeout(100);
await page.reload();
// Timestamp should update with each refresh, because its server rendered.
expect(await page.getByTestId('timestamp').innerText()).not.toEqual(
timestamp,
);
await page.waitForTimeout(100);
// Timestamp should update in the browser because its hydrated.
expect(await page.getByTestId('timestamp').innerText()).not.toEqual(
timestamp,
);
});
// TODO: Add test case for cached RSC payload that should not re-render.
});
});