update tests

pull/12374/head
Rich Harris 2 years ago
parent 9dc2b81c83
commit ec18cc8295

@ -2159,11 +2159,12 @@ export function server_component(analysis, options) {
const body = [...state.hoisted, ...module.body];
if (options.css === 'injected') {
if (analysis.css.ast !== null && options.css === 'injected') {
body.push(
b.const(
'$$css',
b.object([
b.init('hash', b.literal(analysis.css.hash)),
b.init('code', b.literal(render_stylesheet(analysis.source, analysis, options).code))
])
)

@ -133,7 +133,7 @@ export function render(component, options = {}) {
let head = payload.head.out + payload.head.title;
for (const { hash, code } of payload.css) {
head += `<style data-svelte="${hash}">${code}</style>`;
head += `<style id="${hash}">${code}</style>`;
}
return {

@ -0,0 +1,5 @@
<style id="svelte-sg04hs">
.foo.svelte-sg04hs {
color: red;
}
</style>

@ -24,9 +24,13 @@ const { test, run } = suite<SSRTest>(async (config, test_dir) => {
const Component = (await import(`${test_dir}/_output/server/main.svelte.js`)).default;
const expected_html = try_read_file(`${test_dir}/_expected.html`);
const rendered = render(Component, { props: config.props || {} });
const { body, head, css } = rendered;
const { body, head } = rendered;
fs.writeFileSync(`${test_dir}/_actual.html`, body);
fs.writeFileSync(`${test_dir}/_output/rendered.html`, body);
if (head) {
fs.writeFileSync(`${test_dir}/_output/rendered_head.html`, head);
}
try {
assert_html_equal_with_options(body, expected_html || '', {
@ -43,38 +47,17 @@ const { test, run } = suite<SSRTest>(async (config, test_dir) => {
}
}
if (fs.existsSync(`${test_dir}/_expected-head.html`)) {
fs.writeFileSync(`${test_dir}/_actual-head.html`, head);
if (fs.existsSync(`${test_dir}/_expected_head.html`)) {
try {
assert_html_equal_with_options(
head,
fs.readFileSync(`${test_dir}/_expected-head.html`, 'utf-8'),
fs.readFileSync(`${test_dir}/_expected_head.html`, 'utf-8'),
{}
);
} catch (error: any) {
if (should_update_expected()) {
fs.writeFileSync(`${test_dir}/_expected-head.html`, head);
console.log(`Updated ${test_dir}/_expected-head.html.`);
error.message += '\n' + `${test_dir}/main.svelte`;
} else {
throw error;
}
}
}
if (fs.existsSync(`${test_dir}/_expected.css`)) {
fs.writeFileSync(`${test_dir}/_actual.css`, css);
try {
assert.equal(
css.replaceAll('\r', ''),
fs.readFileSync(`${test_dir}/_expected.css`, 'utf-8').replaceAll('\r', '')
);
} catch (error: any) {
if (should_update_expected()) {
fs.writeFileSync(`${test_dir}/_expected.css`, css);
console.log(`Updated ${test_dir}/_expected.css.`);
fs.writeFileSync(`${test_dir}/_expected_head.html`, head);
console.log(`Updated ${test_dir}/_expected_head.html.`);
error.message += '\n' + `${test_dir}/main.svelte`;
} else {
throw error;

Loading…
Cancel
Save