File tree Expand file tree Collapse file tree 3 files changed +15
-4
lines changed
packages/kit/test/prerendering Expand file tree Collapse file tree 3 files changed +15
-4
lines changed Original file line number Diff line number Diff line change 11import * as fs from 'node:fs' ;
22import { fileURLToPath } from 'node:url' ;
33import { assert , expect , test } from 'vitest' ;
4+ import { replace_hydration_attrs } from '../../test-utils' ;
45
56const build = fileURLToPath ( new URL ( '../build' , import . meta. url ) ) ;
67
@@ -146,7 +147,7 @@ test('decodes paths when writing files', () => {
146147} ) ;
147148
148149test ( 'prerendering is set to true in root +layout.js' , ( ) => {
149- const content = read ( 'prerendering-true.html' ) ;
150+ const content = replace_hydration_attrs ( read ( 'prerendering-true.html' ) ) ;
150151 expect ( content ) . toMatch ( '<h1>prerendering: true/true</h1>' ) ;
151152} ) ;
152153
@@ -198,7 +199,7 @@ test('$env - includes environment variables', () => {
198199} ) ;
199200
200201test ( 'prerenders a page in a (group)' , ( ) => {
201- const content = read ( 'grouped.html' ) ;
202+ const content = replace_hydration_attrs ( read ( 'grouped.html' ) ) ;
202203 expect ( content ) . toMatch ( '<h1>grouped</h1>' ) ;
203204} ) ;
204205
Original file line number Diff line number Diff line change 11import * as fs from 'node:fs' ;
22import { fileURLToPath } from 'node:url' ;
33import { assert , expect , test } from 'vitest' ;
4+ import { replace_hydration_attrs } from '../../test-utils' ;
45
56const build = fileURLToPath ( new URL ( '../build' , import . meta. url ) ) ;
67
78/** @param {string } file */
89const read = ( file ) => fs . readFileSync ( `${ build } /${ file } ` , 'utf-8' ) ;
910
1011test ( 'prerenders /path-base' , ( ) => {
11- const content = read ( 'index.html' ) ;
12+ const content = replace_hydration_attrs ( read ( 'index.html' ) ) ;
1213 expect ( content ) . toMatch ( '<h1>hello</h1>' ) ;
1314} ) ;
1415
1516test ( 'prerenders nested /path-base' , ( ) => {
16- const content = read ( 'nested/index.html' ) ;
17+ const content = replace_hydration_attrs ( read ( 'nested/index.html' ) ) ;
1718 expect ( content ) . toMatch ( '<h1>nested hello</h1>' ) ;
1819} ) ;
1920
Original file line number Diff line number Diff line change 1+ /**
2+ * For static content, Svelte v4 will add a data-svelte-h attribute.
3+ * Replace the hash with something predictable before comparing the output.
4+ *
5+ * @param {string } html
6+ */
7+ export function replace_hydration_attrs ( html ) {
8+ return html . replace ( / ( \s + ) d a t a - s v e l t e - h = " s v e l t e - \w + " / g, '' ) ;
9+ }
You can’t perform that action at this time.
0 commit comments