|
|
|
@ -8,7 +8,6 @@ import {
|
|
|
|
loadSvelte,
|
|
|
|
loadSvelte,
|
|
|
|
setupHtmlEqual,
|
|
|
|
setupHtmlEqual,
|
|
|
|
tryToLoadJson,
|
|
|
|
tryToLoadJson,
|
|
|
|
cleanRequireCache,
|
|
|
|
|
|
|
|
shouldUpdateExpected
|
|
|
|
shouldUpdateExpected
|
|
|
|
} from '../helpers';
|
|
|
|
} from '../helpers';
|
|
|
|
import { set_current_component } from '../../internal';
|
|
|
|
import { set_current_component } from '../../internal';
|
|
|
|
@ -55,19 +54,18 @@ describe('ssr', () => {
|
|
|
|
(solo ? it.only : it)(dir, (done) => {
|
|
|
|
(solo ? it.only : it)(dir, (done) => {
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
dir = path.resolve(`${__dirname}/samples`, dir);
|
|
|
|
dir = path.resolve(`${__dirname}/samples`, dir);
|
|
|
|
|
|
|
|
|
|
|
|
cleanRequireCache();
|
|
|
|
register.clearCompileOutputCache();
|
|
|
|
|
|
|
|
register.clearRequireCache();
|
|
|
|
const compileOptions = {
|
|
|
|
const compileOptions = {
|
|
|
|
sveltePath,
|
|
|
|
sveltePath,
|
|
|
|
...config.compileOptions,
|
|
|
|
...config.compileOptions,
|
|
|
|
generate: 'ssr',
|
|
|
|
generate: 'ssr',
|
|
|
|
format: 'cjs'
|
|
|
|
format: 'cjs'
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
register.setCompileOptions(compileOptions);
|
|
|
|
require('../../register')(compileOptions);
|
|
|
|
register.setOutputFolderName('ssr');
|
|
|
|
|
|
|
|
|
|
|
|
const Component = require(`${dir}/main.svelte`).default;
|
|
|
|
const Component = require(`${dir}/main.svelte`).default;
|
|
|
|
|
|
|
|
|
|
|
|
@ -134,6 +132,7 @@ describe('ssr', () => {
|
|
|
|
done();
|
|
|
|
done();
|
|
|
|
} catch (err) {
|
|
|
|
} catch (err) {
|
|
|
|
err.stack += `\n\ncmd-click: ${path.relative(process.cwd(), dir)}/main.svelte`;
|
|
|
|
err.stack += `\n\ncmd-click: ${path.relative(process.cwd(), dir)}/main.svelte`;
|
|
|
|
|
|
|
|
register.writeCompileOutputCacheToFile();
|
|
|
|
done(err);
|
|
|
|
done(err);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
set_current_component(null);
|
|
|
|
set_current_component(null);
|
|
|
|
@ -143,7 +142,7 @@ describe('ssr', () => {
|
|
|
|
|
|
|
|
|
|
|
|
// duplicate client-side tests, as far as possible
|
|
|
|
// duplicate client-side tests, as far as possible
|
|
|
|
runRuntimeSamples('runtime');
|
|
|
|
runRuntimeSamples('runtime');
|
|
|
|
runRuntimeSamples('runtime-puppeteer');
|
|
|
|
// runRuntimeSamples('runtime-puppeteer');
|
|
|
|
|
|
|
|
|
|
|
|
function runRuntimeSamples(suite) {
|
|
|
|
function runRuntimeSamples(suite) {
|
|
|
|
fs.readdirSync(`test/${suite}/samples`).forEach(dir => {
|
|
|
|
fs.readdirSync(`test/${suite}/samples`).forEach(dir => {
|
|
|
|
@ -162,50 +161,54 @@ describe('ssr', () => {
|
|
|
|
const cwd = path.resolve(`test/${suite}/samples`, dir);
|
|
|
|
const cwd = path.resolve(`test/${suite}/samples`, dir);
|
|
|
|
|
|
|
|
|
|
|
|
delete global.window;
|
|
|
|
delete global.window;
|
|
|
|
register.clearRequireCache();
|
|
|
|
|
|
|
|
register.setCompileOptions({
|
|
|
|
|
|
|
|
sveltePath,
|
|
|
|
|
|
|
|
...config.compileOptions,
|
|
|
|
|
|
|
|
generate: 'ssr',
|
|
|
|
|
|
|
|
format: 'cjs'
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
register.setOutputFolderName('ssr');
|
|
|
|
return Promise.resolve()
|
|
|
|
|
|
|
|
.then(() => {
|
|
|
|
try {
|
|
|
|
register.clearCompileOutputCache();
|
|
|
|
if (config.before_test) config.before_test();
|
|
|
|
register.clearRequireCache();
|
|
|
|
|
|
|
|
register.setCompileOptions({
|
|
|
|
const Component = require(`../${suite}/samples/${dir}/main.svelte`).default;
|
|
|
|
sveltePath,
|
|
|
|
const { html } = Component.render(config.props, {
|
|
|
|
...config.compileOptions,
|
|
|
|
store: (config.store !== true) && config.store
|
|
|
|
generate: 'ssr',
|
|
|
|
});
|
|
|
|
format: 'cjs'
|
|
|
|
|
|
|
|
});
|
|
|
|
if (config.ssrHtml) {
|
|
|
|
register.setOutputFolderName('ssr');
|
|
|
|
assert.htmlEqual(html, config.ssrHtml);
|
|
|
|
|
|
|
|
} else if (config.html) {
|
|
|
|
if (config.before_test) config.before_test();
|
|
|
|
assert.htmlEqual(html, config.html);
|
|
|
|
|
|
|
|
}
|
|
|
|
const Component = require(`../${suite}/samples/${dir}/main.svelte`).default;
|
|
|
|
|
|
|
|
const { html } = Component.render(config.props, {
|
|
|
|
if (config.test_ssr) {
|
|
|
|
store: (config.store !== true) && config.store
|
|
|
|
config.test_ssr({ assert });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (config.ssrHtml) {
|
|
|
|
|
|
|
|
assert.htmlEqual(html, config.ssrHtml);
|
|
|
|
|
|
|
|
} else if (config.html) {
|
|
|
|
|
|
|
|
assert.htmlEqual(html, config.html);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (config.after_test) config.after_test();
|
|
|
|
if (config.test_ssr) {
|
|
|
|
} catch (err) {
|
|
|
|
config.test_ssr({ assert });
|
|
|
|
err.stack += `\n\ncmd-click: ${path.relative(process.cwd(), cwd)}/main.svelte`;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (config.error) {
|
|
|
|
if (config.after_test) config.after_test();
|
|
|
|
if (typeof config.error === 'function') {
|
|
|
|
set_current_component(null);
|
|
|
|
config.error(assert, err);
|
|
|
|
}).catch(err => {
|
|
|
|
|
|
|
|
if (config.error) {
|
|
|
|
|
|
|
|
if (typeof config.error === 'function') {
|
|
|
|
|
|
|
|
config.error(assert, err);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
assert.equal(err.message, config.error);
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
assert.equal(err.message, config.error);
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
}).catch(err => {
|
|
|
|
|
|
|
|
err.stack += `\n\ncmd-click: ${path.relative(process.cwd(), cwd)}/main.svelte`;
|
|
|
|
|
|
|
|
register.writeCompileOutputCacheToFile();
|
|
|
|
|
|
|
|
set_current_component(null);
|
|
|
|
throw err;
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
set_current_component(null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|