@@ -10,7 +10,8 @@ import { compile_directory } from '../helpers.js';
1010import { setup_html_equal } from '../html_equal.js' ;
1111import { raf } from '../animation-helpers.js' ;
1212import type { CompileOptions } from '#compiler' ;
13- import { suite_with_variants , type BaseTest } from '../suite.js' ;
13+ import { suite_with_variants , type BaseTest , type TemplatingMode } from '../suite.js' ;
14+ import { seen } from '../../src/internal/server/dev.js' ;
1415
1516type Assert = typeof import ( 'vitest' ) . assert & {
1617 htmlEqual ( a : string , b : string , description ?: string ) : void ;
@@ -141,16 +142,21 @@ export function runtime_suite(runes: boolean) {
141142
142143 return false ;
143144 } ,
144- ( config , cwd ) => {
145- return common_setup ( cwd , runes , config ) ;
145+ ( config , cwd , templating_mode ) => {
146+ return common_setup ( cwd , runes , config , templating_mode ) ;
146147 } ,
147- async ( config , cwd , variant , common ) => {
148- await run_test_variant ( cwd , config , variant , common , runes ) ;
148+ async ( config , cwd , variant , common , templating_mode ) => {
149+ await run_test_variant ( cwd , config , variant , common , runes , templating_mode ) ;
149150 }
150151 ) ;
151152}
152153
153- async function common_setup ( cwd : string , runes : boolean | undefined , config : RuntimeTest ) {
154+ async function common_setup (
155+ cwd : string ,
156+ runes : boolean | undefined ,
157+ config : RuntimeTest ,
158+ templating_mode : TemplatingMode
159+ ) {
154160 const force_hmr = process . env . HMR && config . compileOptions ?. dev !== false && ! config . error ;
155161
156162 const compileOptions : CompileOptions = {
@@ -161,13 +167,14 @@ async function common_setup(cwd: string, runes: boolean | undefined, config: Run
161167 ...config . compileOptions ,
162168 immutable : config . immutable ,
163169 accessors : 'accessors' in config ? config . accessors : true ,
164- runes
170+ runes,
171+ preventTemplateCloning : templating_mode === 'functional'
165172 } ;
166173
167174 // load_compiled can be used for debugging a test. It means the compiler will not run on the input
168175 // so you can manipulate the output manually to see what fixes it, adding console.logs etc.
169176 if ( ! config . load_compiled ) {
170- await compile_directory ( cwd , 'client' , compileOptions ) ;
177+ await compile_directory ( cwd , 'client' , compileOptions , undefined , undefined , templating_mode ) ;
171178 await compile_directory ( cwd , 'server' , compileOptions ) ;
172179 }
173180
@@ -179,7 +186,8 @@ async function run_test_variant(
179186 config : RuntimeTest ,
180187 variant : 'dom' | 'hydrate' | 'ssr' ,
181188 compileOptions : CompileOptions ,
182- runes : boolean
189+ runes : boolean ,
190+ templating_mode : TemplatingMode
183191) {
184192 let unintended_error = false ;
185193
@@ -257,8 +265,15 @@ async function run_test_variant(
257265 raf . reset ( ) ;
258266
259267 // Put things we need on window for testing
260- const styles = globSync ( '**/*.css' , { cwd : `${ cwd } /_output/client` } )
261- . map ( ( file ) => fs . readFileSync ( `${ cwd } /_output/client/${ file } ` , 'utf-8' ) )
268+ const styles = globSync ( '**/*.css' , {
269+ cwd : `${ cwd } /_output/client${ templating_mode === 'functional' ? '-functional' : '' } `
270+ } )
271+ . map ( ( file ) =>
272+ fs . readFileSync (
273+ `${ cwd } /_output/client${ templating_mode === 'functional' ? '-functional' : '' } /${ file } ` ,
274+ 'utf-8'
275+ )
276+ )
262277 . join ( '\n' )
263278 . replace ( / \/ \* < \/ ? s t y l e > \* \/ / g, '' ) ;
264279
@@ -274,26 +289,36 @@ async function run_test_variant(
274289
275290 globalThis . requestAnimationFrame = globalThis . setTimeout ;
276291
277- let mod = await import ( `${ cwd } /_output/client/main.svelte.js` ) ;
292+ let mod = await import (
293+ `${ cwd } /_output/client${ templating_mode === 'functional' ? '-functional' : '' } /main.svelte.js`
294+ ) ;
278295
279296 const target = window . document . querySelector ( 'main' ) as HTMLElement ;
280297
281298 let snapshot = undefined ;
282299
283300 if ( variant === 'hydrate' || variant === 'ssr' ) {
284301 config . before_test ?.( ) ;
302+ // we need to clear the seen messages between tests
303+ seen ?. clear ?.( ) ;
285304 // ssr into target
286305 const SsrSvelteComponent = ( await import ( `${ cwd } /_output/server/main.svelte.js` ) ) . default ;
287306 const { html, head } = render ( SsrSvelteComponent , {
288307 props : config . server_props ?? config . props ?? { } ,
289308 idPrefix : config . id_prefix
290309 } ) ;
291310
292- fs . writeFileSync ( `${ cwd } /_output/rendered.html` , html ) ;
311+ fs . writeFileSync (
312+ `${ cwd } /_output/rendered${ templating_mode === 'functional' ? '-functional' : '' } .html` ,
313+ html
314+ ) ;
293315 target . innerHTML = html ;
294316
295317 if ( head ) {
296- fs . writeFileSync ( `${ cwd } /_output/rendered_head.html` , head ) ;
318+ fs . writeFileSync (
319+ `${ cwd } /_output/rendered_head${ templating_mode === 'functional' ? '-functional' : '' } .html` ,
320+ head
321+ ) ;
297322 window . document . head . innerHTML = window . document . head . innerHTML + head ;
298323 }
299324
0 commit comments