@@ -4,14 +4,14 @@ import * as fs from 'node:fs';
4
4
import { assert } from 'vitest' ;
5
5
import { compile_directory , should_update_expected } from '../helpers.js' ;
6
6
import { assert_html_equal } from '../html_equal.js' ;
7
- import { suite , assert_ok } from '../suite.js' ;
7
+ import { suite , assert_ok , type BaseTest } from '../suite.js' ;
8
8
import { createClassComponent } from 'svelte/legacy' ;
9
+ import { render } from 'svelte/server' ;
9
10
import type { CompileOptions } from '#compiler' ;
10
11
11
- interface HydrationTest {
12
- solo ?: boolean ;
13
- skip ?: boolean ;
12
+ interface HydrationTest extends BaseTest {
14
13
load_compiled ?: boolean ;
14
+ server_props ?: Record < string , any > ;
15
15
props ?: Record < string , any > ;
16
16
compileOptions ?: Partial < CompileOptions > ;
17
17
/**
@@ -53,14 +53,16 @@ const { test, run } = suite<HydrationTest>(async (config, cwd) => {
53
53
const target = window . document . body ;
54
54
const head = window . document . head ;
55
55
56
- target . innerHTML = read_html ( `${ cwd } /_before.html` ) ;
56
+ const rendered = render ( ( await import ( `${ cwd } /_output/server/main.svelte.js` ) ) . default , {
57
+ props : config . server_props ?? config . props ?? { }
58
+ } ) ;
57
59
58
- let before_head ;
59
- try {
60
- before_head = read_html ( ` ${ cwd } /_before_head.html` ) ;
61
- head . innerHTML = before_head ;
62
- } catch ( err ) {
63
- // continue regardless of error
60
+ fs . writeFileSync ( ` ${ cwd } /_output/body.html` , rendered . html + '\n' ) ;
61
+ target . innerHTML = rendered . html ;
62
+
63
+ if ( rendered . head ) {
64
+ fs . writeFileSync ( ` ${ cwd } /_output/head.html` , rendered . head + '\n' ) ;
65
+ head . innerHTML = rendered . head ;
64
66
}
65
67
66
68
config . before_test ?.( ) ;
@@ -106,7 +108,7 @@ const { test, run } = suite<HydrationTest>(async (config, cwd) => {
106
108
}
107
109
}
108
110
109
- if ( before_head ) {
111
+ if ( rendered . head ) {
110
112
try {
111
113
const after_head = read_html ( `${ cwd } /_after_head.html` , `${ cwd } /_before_head.html` ) ;
112
114
assert_html_equal ( head . innerHTML , after_head ) ;
0 commit comments