1
1
import fetch from 'node-fetch'
2
2
import { expect , test } from 'vitest'
3
3
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'
5
11
6
12
const url = `http://localhost:${ port } `
7
13
8
14
test ( '/env' , async ( ) => {
9
- await page . goto ( url + '/env' )
15
+ await untilBrowserLogAfter ( ( ) => page . goto ( url + '/env' ) , 'hydrated' )
16
+
10
17
expect ( await page . textContent ( 'h1' ) ) . toMatch ( 'default message here' )
11
18
12
19
// raw http request
@@ -15,7 +22,8 @@ test('/env', async () => {
15
22
} )
16
23
17
24
test ( '/about' , async ( ) => {
18
- await page . goto ( url + '/about' )
25
+ await untilBrowserLogAfter ( ( ) => page . goto ( url + '/about' ) , 'hydrated' )
26
+
19
27
expect ( await page . textContent ( 'h1' ) ) . toMatch ( 'About' )
20
28
// should not have hydration mismatch
21
29
browserLogs . forEach ( ( msg ) => {
@@ -28,7 +36,8 @@ test('/about', async () => {
28
36
} )
29
37
30
38
test ( '/' , async ( ) => {
31
- await page . goto ( url )
39
+ await untilBrowserLogAfter ( ( ) => page . goto ( url ) , 'hydrated' )
40
+
32
41
expect ( await page . textContent ( 'h1' ) ) . toMatch ( 'Home' )
33
42
// should not have hydration mismatch
34
43
browserLogs . forEach ( ( msg ) => {
@@ -49,7 +58,8 @@ test('hmr', async () => {
49
58
} )
50
59
51
60
test ( 'client navigation' , async ( ) => {
52
- await page . goto ( url )
61
+ await untilBrowserLogAfter ( ( ) => page . goto ( url ) , 'hydrated' )
62
+
53
63
await untilUpdated ( ( ) => page . textContent ( 'a[href="/about"]' ) , 'About' )
54
64
await page . click ( 'a[href="/about"]' )
55
65
await untilUpdated ( ( ) => page . textContent ( 'h1' ) , 'About' )
0 commit comments