Skip to content

Commit c45c984

Browse files
authored
test: reduce ssr-react playground flakiness (#11077)
1 parent 615c768 commit c45c984

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

playground/ssr-react/__tests__/ssr-react.spec.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import fetch from 'node-fetch'
22
import { expect, test } from 'vitest'
33
import { port } from './serve'
4-
import { browserLogs, editFile, page, untilUpdated } from '~utils'
4+
import {
5+
browserLogs,
6+
editFile,
7+
page,
8+
untilBrowserLogAfter,
9+
untilUpdated
10+
} from '~utils'
511

612
const url = `http://localhost:${port}`
713

814
test('/env', async () => {
9-
await page.goto(url + '/env')
15+
await untilBrowserLogAfter(() => page.goto(url + '/env'), 'hydrated')
16+
1017
expect(await page.textContent('h1')).toMatch('default message here')
1118

1219
// raw http request
@@ -15,7 +22,8 @@ test('/env', async () => {
1522
})
1623

1724
test('/about', async () => {
18-
await page.goto(url + '/about')
25+
await untilBrowserLogAfter(() => page.goto(url + '/about'), 'hydrated')
26+
1927
expect(await page.textContent('h1')).toMatch('About')
2028
// should not have hydration mismatch
2129
browserLogs.forEach((msg) => {
@@ -28,7 +36,8 @@ test('/about', async () => {
2836
})
2937

3038
test('/', async () => {
31-
await page.goto(url)
39+
await untilBrowserLogAfter(() => page.goto(url), 'hydrated')
40+
3241
expect(await page.textContent('h1')).toMatch('Home')
3342
// should not have hydration mismatch
3443
browserLogs.forEach((msg) => {
@@ -49,7 +58,8 @@ test('hmr', async () => {
4958
})
5059

5160
test('client navigation', async () => {
52-
await page.goto(url)
61+
await untilBrowserLogAfter(() => page.goto(url), 'hydrated')
62+
5363
await untilUpdated(() => page.textContent('a[href="/about"]'), 'About')
5464
await page.click('a[href="/about"]')
5565
await untilUpdated(() => page.textContent('h1'), 'About')

playground/ssr-react/src/entry-client.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ ReactDOM.hydrateRoot(
88
<App />
99
</BrowserRouter>
1010
)
11+
console.log('hydrated')

0 commit comments

Comments
 (0)