update tests

This commit is contained in:
Rich Harris
2018-09-30 11:32:58 -04:00
parent 2185f89669
commit 5573258a10
10 changed files with 39 additions and 40 deletions

1
.gitignore vendored
View File

@@ -5,6 +5,7 @@ node_modules
cypress/screenshots cypress/screenshots
test/app/.sapper test/app/.sapper
test/app/src/manifest test/app/src/manifest
__sapper__
test/app/export test/app/export
test/app/build test/app/build
sapper sapper

1
index.js Normal file
View File

@@ -0,0 +1 @@
throw new Error(`As of Sapper 0.22, you should not import 'sapper' directly. See https://sapper.svelte.technology/guide#0-21-to-0-22 for more information`);

View File

@@ -1 +0,0 @@
This directory exists for legacy reasons and should be deleted before releasing version 1.

View File

@@ -1,2 +0,0 @@
console.error('sapper/runtime/app.js has been deprecated in favour of sapper/runtime.js');
export * from '../runtime.js';

View File

@@ -73,24 +73,30 @@ function generate_client(
const server_routes_to_ignore = manifest_data.server_routes.filter(route => const server_routes_to_ignore = manifest_data.server_routes.filter(route =>
!page_ids.has(route.pattern.toString())); !page_ids.has(route.pattern.toString()));
const component_indexes: Record<string, number> = {};
let code = ` let code = `
import root from ${stringify(get_file(path_to_routes, manifest_data.root))}; import root from ${stringify(get_file(path_to_routes, manifest_data.root))};
import error from ${stringify(posixify(`${path_to_routes}/_error.html`))}; import error from ${stringify(posixify(`${path_to_routes}/_error.html`))};
const d = decodeURIComponent; const d = decodeURIComponent;
${manifest_data.components.map(component => { const components = [
${manifest_data.components.map((component, i) => {
const annotation = bundler === 'webpack' const annotation = bundler === 'webpack'
? `/* webpackChunkName: "${component.name}" */ ` ? `/* webpackChunkName: "${component.name}" */ `
: ''; : '';
const source = get_file(path_to_routes, component); const source = get_file(path_to_routes, component);
return `const ${component.name} = { component_indexes[component.name] = i;
return `{
js: () => import(${annotation}${stringify(source)}), js: () => import(${annotation}${stringify(source)}),
css: "__SAPPER_CSS_PLACEHOLDER:${stringify(component.file, false)}__" css: "__SAPPER_CSS_PLACEHOLDER:${stringify(component.file, false)}__"
};`; }`;
}).join('\n')} }).join(',\n\t\t\t')}
];
const manifest = { const manifest = {
ignore: [${server_routes_to_ignore.map(route => route.pattern).join(', ')}], ignore: [${server_routes_to_ignore.map(route => route.pattern).join(', ')}],
@@ -105,10 +111,10 @@ function generate_client(
if (part.params.length > 0) { if (part.params.length > 0) {
const props = part.params.map((param, i) => `${param}: d(match[${i + 1}])`); const props = part.params.map((param, i) => `${param}: d(match[${i + 1}])`);
return `{ component: ${part.component.name}, params: match => ({ ${props.join(', ')} }) }`; return `{ component: components[${component_indexes[part.component.name]}], params: match => ({ ${props.join(', ')} }) }`;
} }
return `{ component: ${part.component.name} }`; return `{ component: components[${component_indexes[part.component.name]}] }`;
}).join(',\n\t\t\t\t\t\t')} }).join(',\n\t\t\t\t\t\t')}
] ]
}`).join(',\n\n\t\t\t\t')} }`).join(',\n\n\t\t\t\t')}
@@ -144,9 +150,9 @@ function generate_server(
const imports = [].concat( const imports = [].concat(
manifest_data.server_routes.map(route => manifest_data.server_routes.map(route =>
`import * as ${route.name} from ${stringify(posixify(`${path_to_routes}/${route.file}`))};`), `import * as __${route.name} from ${stringify(posixify(`${path_to_routes}/${route.file}`))};`),
manifest_data.components.map(component => manifest_data.components.map(component =>
`import ${component.name} from ${stringify(get_file(path_to_routes, component))};`), `import __${component.name} from ${stringify(get_file(path_to_routes, component))};`),
`import root from ${stringify(get_file(path_to_routes, manifest_data.root))};`, `import root from ${stringify(get_file(path_to_routes, manifest_data.root))};`,
`import error from ${stringify(posixify(`${path_to_routes}/_error.html`))};` `import error from ${stringify(posixify(`${path_to_routes}/_error.html`))};`
); );
@@ -161,7 +167,7 @@ function generate_server(
${manifest_data.server_routes.map(route => `{ ${manifest_data.server_routes.map(route => `{
// ${route.file} // ${route.file}
pattern: ${route.pattern}, pattern: ${route.pattern},
handlers: ${route.name}, handlers: __${route.name},
params: ${route.params.length > 0 params: ${route.params.length > 0
? `match => ({ ${route.params.map((param, i) => `${param}: d(match[${i + 1}])`).join(', ')} })` ? `match => ({ ${route.params.map((param, i) => `${param}: d(match[${i + 1}])`).join(', ')} })`
: `() => ({})`} : `() => ({})`}
@@ -179,7 +185,7 @@ function generate_server(
const props = [ const props = [
`name: "${part.component.name}"`, `name: "${part.component.name}"`,
`file: ${stringify(part.component.file)}`, `file: ${stringify(part.component.file)}`,
`component: ${part.component.name}` `component: __${part.component.name}`
]; ];
if (part.params.length > 0) { if (part.params.length > 0) {

View File

@@ -1,14 +1,12 @@
import { init, goto, prefetchRoutes } from '../../../runtime.js';
import { Store } from 'svelte/store.js'; import { Store } from 'svelte/store.js';
import { manifest } from './manifest/client.js'; import * as sapper from './__sapper__/client.js';
window.init = () => { window.init = () => {
return init({ return sapper.start({
target: document.querySelector('#sapper'), target: document.querySelector('#sapper'),
manifest,
store: data => new Store(data) store: data => new Store(data)
}); });
}; };
window.prefetchRoutes = prefetchRoutes; window.prefetchRoutes = sapper.prefetchRoutes;
window.goto = goto; window.goto = sapper.goto;

View File

@@ -9,17 +9,9 @@
<button class='prefetch' on:click='prefetch("blog/why-the-name")'>Why the name?</button> <button class='prefetch' on:click='prefetch("blog/why-the-name")'>Why the name?</button>
<script> <script>
import { goto, prefetch } from '../../../../runtime.js'; import { prefetch } from '../__sapper__/client.js';
export default { export default {
oncreate() {
window.goto = goto;
},
ondestroy() {
window.goto = null;
},
methods: { methods: {
prefetch prefetch
} }

View File

@@ -2,9 +2,8 @@ import fs from 'fs';
import { resolve } from 'url'; import { resolve } from 'url';
import express from 'express'; import express from 'express';
import serve from 'serve-static'; import serve from 'serve-static';
import sapper from '../../../dist/middleware.js';
import { Store } from 'svelte/store.js'; import { Store } from 'svelte/store.js';
import { manifest } from './manifest/server.js'; import * as sapper from './__sapper__/server.js';
let pending; let pending;
let ended; let ended;
@@ -92,8 +91,7 @@ const middlewares = [
next(); next();
}, },
sapper({ sapper.middleware({
manifest,
store: (req, res) => { store: (req, res) => {
return new Store({ return new Store({
title: `${req.hello} ${res.locals.name}` title: `${req.hello} ${res.locals.name}`

View File

@@ -1,10 +1,10 @@
import { assets, shell, timestamp, routes } from './manifest/service-worker.js'; import { files, shell, timestamp, routes } from './__sapper__/service-worker.js';
const ASSETS = `cachetimestamp`; const ASSETS = `cachetimestamp`;
// `shell` is an array of all the files generated by webpack, // `shell` is an array of all the files generated by webpack,
// `assets` is an array of everything in the `assets` directory // `assets` is an array of everything in the `assets` directory
const to_cache = shell.concat(assets); const to_cache = shell.concat(files);
const cached = new Set(to_cache); const cached = new Set(to_cache);
self.addEventListener('install', event => { self.addEventListener('install', event => {

View File

@@ -29,6 +29,9 @@ module.exports = {
] ]
}, },
mode, mode,
optimization: {
minimize: false
},
plugins: [ plugins: [
isDev && new webpack.HotModuleReplacementPlugin() isDev && new webpack.HotModuleReplacementPlugin()
].filter(Boolean), ].filter(Boolean),
@@ -64,6 +67,9 @@ module.exports = {
] ]
}, },
mode, mode,
optimization: {
minimize: false
},
performance: { performance: {
hints: false // it doesn't matter if server.js is large hints: false // it doesn't matter if server.js is large
} }