all tests passing

This commit is contained in:
Rich Harris
2018-07-16 16:23:43 -04:00
parent b0b8b78c5d
commit 1f66e4c530
3 changed files with 22 additions and 16 deletions

View File

@@ -62,7 +62,8 @@ function generate_client(
import error from '${posixify(`${path_to_routes}/_error.html`)}';
${routes.components.map(component =>
`const ${right_pad(component.name, len)} = () => import('${posixify(`${path_to_routes}/${component.file}`)}');`)
`const ${component.name} = () =>
import(/* webpackChunkName: "${component.name}" */ '${posixify(`${path_to_routes}/${component.file}`)}');`)
.join('\n')}
export const routes = {
@@ -142,12 +143,17 @@ function generate_server(
pattern: ${page.pattern},
parts: [
${page.parts.map(part => {
const props = [
`name: "${part.component.name}"`,
`component: ${part.component.name}`
];
if (part.params.length > 0) {
const props = part.params.map((param, i) => `${param}: match[${i + 1}]`);
return `{ component: ${part.component.name}, params: match => ({ ${props.join(', ')} }) }`;
const params = part.params.map((param, i) => `${param}: match[${i + 1}]`);
props.push(`params: match => ({ ${params.join(', ')} })`);
}
return `{ component: ${part.component.name} }`;
return `{ ${props.join(', ')} }`;
}).join(',\n\t\t\t\t\t\t')}
]
}`).join(',\n\n\t\t\t\t')}

View File

@@ -20,6 +20,7 @@ type ServerRoute = {
type Page = {
pattern: RegExp;
parts: Array<{
name: string;
component: Component;
params?: (match: RegExpMatchArray) => Record<string, string>;
}>
@@ -261,8 +262,7 @@ function get_page_handler(routes: RouteObject, store_getter: (req: Req) => Store
// preload main.js and current route
// TODO detect other stuff we can preload? images, CSS, fonts?
const link = []
// TODO reinstate this!
// .concat(chunks.main, chunks[page.id] || chunks._error) // TODO this is gross
.concat(chunks.main, error ? [] : page.parts.map(part => chunks[part.name]))
.filter(file => !file.match(/\.map$/))
.map(file => `<${req.baseUrl}/client/${file}>;rel="preload";as="script"`)
.join(', ');
@@ -346,7 +346,7 @@ function get_page_handler(routes: RouteObject, store_getter: (req: Req) => Store
handle_page({
pattern: null,
parts: [
{ component: error_route }
{ name: null, component: error_route }
]
}, req, res, preload_error.statusCode, preload_error.message);
@@ -438,7 +438,7 @@ function get_page_handler(routes: RouteObject, store_getter: (req: Req) => Store
handle_page({
pattern: null,
parts: [
{ component: error_route }
{ name: null, component: error_route }
]
}, req, res, 404, 'Not found');
};

View File

@@ -41,7 +41,7 @@ describe('sapper', function() {
rimraf.sync('.sapper');
rimraf.sync('start.js');
this.timeout(process.env.CI ? 30000 : 10000);
this.timeout(process.env.CI ? 30000 : 15000);
// TODO reinstate dev tests
// run({
@@ -97,13 +97,13 @@ describe('sapper', function() {
];
// Client scripts that should show up in the extraction directory.
const expectedClientRegexes = [
/client\/[^/]+\/_(\.\d+)?\.js/,
/client\/[^/]+\/about(\.\d+)?\.js/,
/client\/[^/]+\/blog_\$slug\$(\.\d+)?\.js/,
/client\/[^/]+\/blog(\.\d+)?\.js/,
/client\/[^/]+\/main(\.\d+)?\.js/,
/client\/[^/]+\/show_url(\.\d+)?\.js/,
/client\/[^/]+\/slow_preload(\.\d+)?\.js/,
/client\/[^/]+\/page_index(\.\d+)?\.js/,
/client\/[^/]+\/page_about(\.\d+)?\.js/,
/client\/[^/]+\/page_blog_\$slug(\.\d+)?\.js/,
/client\/[^/]+\/page_blog(\.\d+)?\.js/,
/client\/[^/]+\/page_show\$45url(\.\d+)?\.js/,
/client\/[^/]+\/page_slow\$45preload(\.\d+)?\.js/,
];
const allPages = walkSync(dest);
@@ -641,7 +641,7 @@ function run({ mode, basepath = '' }) {
'text/html'
);
const str = ['main', '_\\.\\d+']
const str = ['main', '.+?\\.\\d+']
.map(file => {
return `<${basepath}/client/[^/]+/${file}\\.js>;rel="preload";as="script"`;
})