chore: add static test

hydratable-flag
paoloricciuti 10 months ago
parent a582f9364f
commit eaf8973923

@ -1,5 +1,5 @@
import { test } from '../../test'; import { test } from '../../test';
export default test({ export default test({
hydratable: false static: true
}); });

@ -6,7 +6,7 @@
import * as fs from 'node:fs'; import * as fs from 'node:fs';
import { assert } from 'vitest'; import { assert } from 'vitest';
import { render } from 'svelte/server'; import { render, renderStaticHTML } from 'svelte/server';
import { compile_directory, should_update_expected, try_read_file } from '../helpers.js'; import { compile_directory, should_update_expected, try_read_file } from '../helpers.js';
import { assert_html_equal_with_options } from '../html_equal.js'; import { assert_html_equal_with_options } from '../html_equal.js';
import { suite, type BaseTest } from '../suite.js'; import { suite, type BaseTest } from '../suite.js';
@ -15,7 +15,7 @@ import type { CompileOptions } from '#compiler';
interface SSRTest extends BaseTest { interface SSRTest extends BaseTest {
compileOptions?: Partial<CompileOptions>; compileOptions?: Partial<CompileOptions>;
props?: Record<string, any>; props?: Record<string, any>;
hydratable?: boolean; static?: boolean;
withoutNormalizeHtml?: boolean; withoutNormalizeHtml?: boolean;
errors?: string[]; errors?: string[];
} }
@ -34,8 +34,8 @@ const { test, run } = suite<SSRTest>(async (config, test_dir) => {
const Component = (await import(`${test_dir}/_output/server/main.svelte.js`)).default; const Component = (await import(`${test_dir}/_output/server/main.svelte.js`)).default;
const expected_html = try_read_file(`${test_dir}/_expected.html`); const expected_html = try_read_file(`${test_dir}/_expected.html`);
console.log({ config }); let fn = config.static === true ? renderStaticHTML : render;
const rendered = render(Component, { props: config.props || {}, hydratable: config.hydratable }); const rendered = fn(Component, { props: config.props || {} });
const { body, head } = rendered; const { body, head } = rendered;
fs.writeFileSync(`${test_dir}/_output/rendered.html`, body); fs.writeFileSync(`${test_dir}/_output/rendered.html`, body);

Loading…
Cancel
Save