11import {
2- readFileContent ,
32 editFile ,
43 editFileAndWaitForHmrComplete ,
54 getColor ,
65 getEl ,
76 getText ,
87 isBuild ,
8+ readFileContent ,
9+ sleep ,
910 untilUpdated
1011} from '../../testUtils' ;
1112
@@ -14,12 +15,37 @@ import path from 'path';
1415
1516describe ( 'kit-node' , ( ) => {
1617 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' ) ;
2031
32+ // also get page as text to confirm
2133 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+
2349 if ( isBuild ) {
2450 // TODO additional testing needed here once vite-plugin-svelte implements indexHtmlTransform hook
2551 }
@@ -51,7 +77,7 @@ describe('kit-node', () => {
5177
5278 it ( 'should load dynamic import in onMount' , async ( ) => {
5379 // 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 ) ;
5581 } ) ;
5682
5783 if ( isBuild ) {
0 commit comments