1
1
import {
2
- readFileContent ,
3
2
editFile ,
4
3
editFileAndWaitForHmrComplete ,
5
4
getColor ,
6
5
getEl ,
7
6
getText ,
8
7
isBuild ,
8
+ readFileContent ,
9
+ sleep ,
9
10
untilUpdated
10
11
} from '../../testUtils' ;
11
12
@@ -14,12 +15,37 @@ import path from 'path';
14
15
15
16
describe ( 'kit-node' , ( ) => {
16
17
describe ( 'index route' , ( ) => {
17
- it ( 'should contain greeting' , async ( ) => {
18
- // TODO is hydration testing needed here?
19
- expect ( await page . textContent ( 'h1' ) ) . toMatch ( 'Hello world!' ) ; // after hydration
18
+ it ( 'should hydrate' , async ( ) => {
19
+ // mark initial nodes
20
+ await page . $eval ( '#load' , ( e ) => {
21
+ e [ '__initialNode' ] = true ;
22
+ } ) ;
23
+ await page . $eval ( '#mount' , ( e ) => {
24
+ e [ '__initialNode' ] = true ;
25
+ } ) ;
26
+
27
+ // check content before hydration
28
+ expect ( await getText ( 'h1' ) ) . toBe ( 'Hello world!' ) ;
29
+ expect ( await getText ( '#load' ) ) . toBe ( 'SERVER_LOADED' ) ;
30
+ expect ( await getText ( '#mount' ) ) . toBe ( 'BEFORE_MOUNT' ) ;
20
31
32
+ // also get page as text to confirm
21
33
const html = await ( await fetch ( page . url ( ) ) ) . text ( ) ;
22
- expect ( html ) . toMatch ( 'Hello world!' ) ; // before hydration
34
+ expect ( html ) . toMatch ( 'Hello world!' ) ;
35
+ expect ( html ) . toMatch ( 'SERVER_LOADED' ) ;
36
+ expect ( html ) . toMatch ( 'BEFORE_MOUNT' ) ;
37
+
38
+ // wait a bit for hydration to kick in
39
+ await sleep ( 250 ) ;
40
+
41
+ // check hydrated content
42
+ expect ( await getText ( '#load' ) ) . toBe ( 'CLIENT_LOADED' ) ;
43
+ expect ( await getText ( '#mount' ) ) . toBe ( 'AFTER_MOUNT' ) ;
44
+
45
+ // check that it did not replace the dom elements with new ones
46
+ expect ( await page . $eval ( '#load' , ( e ) => e [ '__initialNode' ] ) ) . toBe ( true ) ;
47
+ expect ( await page . $eval ( '#mount' , ( e ) => e [ '__initialNode' ] ) ) . toBe ( true ) ;
48
+
23
49
if ( isBuild ) {
24
50
// TODO additional testing needed here once vite-plugin-svelte implements indexHtmlTransform hook
25
51
}
@@ -51,7 +77,7 @@ describe('kit-node', () => {
51
77
52
78
it ( 'should load dynamic import in onMount' , async ( ) => {
53
79
// expect log to contain message with dynamic import value from onMount
54
- expect ( browserLogs . some ( ( x ) => x === ` onMount dynamic imported isSSR: false` ) ) . toBe ( true ) ;
80
+ expect ( browserLogs . some ( ( x ) => x === ' onMount dynamic imported isSSR: false' ) ) . toBe ( true ) ;
55
81
} ) ;
56
82
57
83
if ( isBuild ) {
0 commit comments