@ -34,17 +34,11 @@ interface HydrationTest extends BaseTest {
after_test ? : ( ) = > void ;
after_test ? : ( ) = > void ;
}
}
const { test , run } = suite < HydrationTest > ( async ( config , cwd ) = > {
function read ( path : string ) : string | void {
/ * *
return fs . existsSync ( path ) ? fs . readFileSync ( path , 'utf-8' ) : undefined ;
* Read file and remove whitespace between ssr comments
}
* /
function read_html ( path : string , fallback? : string ) : string {
const html = fs . readFileSync ( fallback && ! fs . existsSync ( path ) ? fallback : path , 'utf-8' ) ;
return config . trim_whitespace !== false
? html . replace ( /(<!--ssr:.?-->)[ \t\n\r\f]+(<!--ssr:.?-->)/g , '$1$2' )
: html ;
}
const { test , run } = suite < HydrationTest > ( async ( config , cwd ) = > {
if ( ! config . load_compiled ) {
if ( ! config . load_compiled ) {
await compile_directory ( cwd , 'client' , { accessors : true , . . . config . compileOptions } ) ;
await compile_directory ( cwd , 'client' , { accessors : true , . . . config . compileOptions } ) ;
await compile_directory ( cwd , 'server' , config . compileOptions ) ;
await compile_directory ( cwd , 'server' , config . compileOptions ) ;
@ -58,7 +52,7 @@ const { test, run } = suite<HydrationTest>(async (config, cwd) => {
} ) ;
} ) ;
fs . writeFileSync ( ` ${ cwd } /_output/body.html ` , rendered . html + '\n' ) ;
fs . writeFileSync ( ` ${ cwd } /_output/body.html ` , rendered . html + '\n' ) ;
target . innerHTML = re ndered. html ;
target . innerHTML = re ad( ` ${ cwd } /_override.html ` ) ? ? re ndered. html ;
if ( rendered . head ) {
if ( rendered . head ) {
fs . writeFileSync ( ` ${ cwd } /_output/head.html ` , rendered . head + '\n' ) ;
fs . writeFileSync ( ` ${ cwd } /_output/head.html ` , rendered . head + '\n' ) ;
@ -97,15 +91,11 @@ const { test, run } = suite<HydrationTest>(async (config, cwd) => {
assert . ok ( ! got_hydration_error , 'Unexpected hydration error' ) ;
assert . ok ( ! got_hydration_error , 'Unexpected hydration error' ) ;
}
}
const expected = fs . existsSync ( ` ${ cwd } /_expected.html ` )
const expected = read ( ` ${ cwd } /_expected.html ` ) ? ? rendered . html ;
? read_html ( ` ${ cwd } /_expected.html ` )
: rendered . html ;
assert_html_equal ( target . innerHTML , expected ) ;
assert_html_equal ( target . innerHTML , expected ) ;
if ( rendered . head ) {
if ( rendered . head ) {
const expected = fs . existsSync ( ` ${ cwd } /_expected_head.html ` )
const expected = read ( ` ${ cwd } /_expected_head.html ` ) ? ? rendered . head ;
? read_html ( ` ${ cwd } /_expected_head.html ` )
: rendered . head ;
assert_html_equal ( head . innerHTML , expected ) ;
assert_html_equal ( head . innerHTML , expected ) ;
}
}