MCPcopy
hub / github.com/sveltejs/svelte / run_ssr_test

Function run_ssr_test

packages/svelte/tests/runtime-browser/test-ssr.ts:15–43  ·  view source on GitHub ↗
(
	config: ReturnType<typeof import('./assert').test>,
	test_dir: string
)

Source from the content-addressed store, hash-verified

13import { describe } from 'vitest';
14
15export async function run_ssr_test(
16 config: ReturnType<typeof import('./assert').test>,
17 test_dir: string
18) {
19 try {
20 await compile_directory(test_dir, 'server', config.compileOptions);
21
22 const Component = (await import(`${test_dir}/_output/server/main.svelte.js`)).default;
23 const { body } = render(Component, { props: config.props || {}, idPrefix: config.id_prefix });
24
25 fs.writeFileSync(`${test_dir}/_output/rendered.html`, body);
26
27 if (config.ssrHtml) {
28 assert_html_equal_with_options(body, config.ssrHtml, {
29 preserveComments: config.compileOptions?.preserveComments
30 });
31 } else if (config.html) {
32 assert_html_equal_with_options(body, config.html, {
33 preserveComments: config.compileOptions?.preserveComments
34 });
35 }
36 } catch (err: any) {
37 err.stack += `\n\ncmd-click: ${path.relative(process.cwd(), test_dir)}/main.svelte`;
38 throw err;
39 }
40
41 // wait for vitest to report progress
42 await setImmediate();
43}
44
45const { run } = suite<ReturnType<typeof import('./assert').test>>(async (config, test_dir) => {
46 if (config.mode && !config.mode.includes('server')) return;

Callers 1

test-ssr.tsFile · 0.85

Calls 3

compile_directoryFunction · 0.90
renderFunction · 0.90

Tested by

no test coverage detected