-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
ssr-react.spec.ts
55 lines (48 loc) · 1.39 KB
/
ssr-react.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
import {
editFile,
getColor,
isBuild,
untilUpdated,
autoRetry
} from '../../testUtils'
import { port } from './serve'
import fetch from 'node-fetch'
const url = `http://localhost:${port}`
test('/about', async () => {
await page.goto(url + '/about')
expect(await page.textContent('h1')).toMatch('About')
// should not have hydration mismatch
browserLogs.forEach((msg) => {
expect(msg).not.toMatch('Expected server HTML')
})
// raw http request
const aboutHtml = await (await fetch(url + '/about')).text()
expect(aboutHtml).toMatch('About')
})
test('/', async () => {
await page.goto(url)
expect(await page.textContent('h1')).toMatch('Home')
// should not have hydration mismatch
browserLogs.forEach((msg) => {
expect(msg).not.toMatch('Expected server HTML')
})
// raw http request
const html = await (await fetch(url)).text()
expect(html).toMatch('Home')
})
test('hmr', async () => {
editFile('src/pages/Home.jsx', (code) =>
code.replace('<h1>Home', '<h1>changed')
)
await untilUpdated(() => page.textContent('h1'), 'changed')
})
test('client navigation', async () => {
await page.click('a[href="/about"]')
await autoRetry(async () => {
expect(await page.textContent('h1')).toMatch('About')
})
editFile('src/pages/About.jsx', (code) =>
code.replace('<h1>About', '<h1>changed')
)
await untilUpdated(() => page.textContent('h1'), 'changed')
})