Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Sep 30, 2018
1 parent 2185f89 commit 5573258
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 40 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ node_modules
cypress/screenshots
test/app/.sapper
test/app/src/manifest
__sapper__
test/app/export
test/app/build
sapper
Expand Down
1 change: 1 addition & 0 deletions index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion runtime/README.md

This file was deleted.

2 changes: 0 additions & 2 deletions runtime/app.js

This file was deleted.

38 changes: 22 additions & 16 deletions src/core/create_manifests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,30 @@ function generate_client(
const server_routes_to_ignore = manifest_data.server_routes.filter(route =>
!page_ids.has(route.pattern.toString()));

const component_indexes: Record<string, number> = {};

let code = `
import root from ${stringify(get_file(path_to_routes, manifest_data.root))};
import error from ${stringify(posixify(`${path_to_routes}/_error.html`))};
const d = decodeURIComponent;
${manifest_data.components.map(component => {
const annotation = bundler === 'webpack'
? `/* webpackChunkName: "${component.name}" */ `
: '';
const components = [
${manifest_data.components.map((component, i) => {
const annotation = bundler === 'webpack'
? `/* webpackChunkName: "${component.name}" */ `
: '';
const source = get_file(path_to_routes, component);
const source = get_file(path_to_routes, component);
component_indexes[component.name] = i;
return `const ${component.name} = {
js: () => import(${annotation}${stringify(source)}),
css: "__SAPPER_CSS_PLACEHOLDER:${stringify(component.file, false)}__"
};`;
}).join('\n')}
return `{
js: () => import(${annotation}${stringify(source)}),
css: "__SAPPER_CSS_PLACEHOLDER:${stringify(component.file, false)}__"
}`;
}).join(',\n\t\t\t')}
];
const manifest = {
ignore: [${server_routes_to_ignore.map(route => route.pattern).join(', ')}],
Expand All @@ -105,10 +111,10 @@ function generate_client(
if (part.params.length > 0) {
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\n\t\t\t\t')}
Expand Down Expand Up @@ -144,9 +150,9 @@ function generate_server(

const imports = [].concat(
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 =>
`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 error from ${stringify(posixify(`${path_to_routes}/_error.html`))};`
);
Expand All @@ -161,7 +167,7 @@ function generate_server(
${manifest_data.server_routes.map(route => `{
// ${route.file}
pattern: ${route.pattern},
handlers: ${route.name},
handlers: __${route.name},
params: ${route.params.length > 0
? `match => ({ ${route.params.map((param, i) => `${param}: d(match[${i + 1}])`).join(', ')} })`
: `() => ({})`}
Expand All @@ -179,7 +185,7 @@ function generate_server(
const props = [
`name: "${part.component.name}"`,
`file: ${stringify(part.component.file)}`,
`component: ${part.component.name}`
`component: __${part.component.name}`
];
if (part.params.length > 0) {
Expand Down
10 changes: 4 additions & 6 deletions test/app/src/client.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { init, goto, prefetchRoutes } from '../../../runtime.js';
import { Store } from 'svelte/store.js';
import { manifest } from './manifest/client.js';
import * as sapper from './__sapper__/client.js';

window.init = () => {
return init({
return sapper.start({
target: document.querySelector('#sapper'),
manifest,
store: data => new Store(data)
});
};

window.prefetchRoutes = prefetchRoutes;
window.goto = goto;
window.prefetchRoutes = sapper.prefetchRoutes;
window.goto = sapper.goto;
10 changes: 1 addition & 9 deletions test/app/src/routes/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,9 @@ <h1>About this site</h1>
<button class='prefetch' on:click='prefetch("blog/why-the-name")'>Why the name?</button>

<script>
import { goto, prefetch } from '../../../../runtime.js';
import { prefetch } from '../__sapper__/client.js';

export default {
oncreate() {
window.goto = goto;
},

ondestroy() {
window.goto = null;
},

methods: {
prefetch
}
Expand Down
6 changes: 2 additions & 4 deletions test/app/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import fs from 'fs';
import { resolve } from 'url';
import express from 'express';
import serve from 'serve-static';
import sapper from '../../../dist/middleware.js';
import { Store } from 'svelte/store.js';
import { manifest } from './manifest/server.js';
import * as sapper from './__sapper__/server.js';

let pending;
let ended;
Expand Down Expand Up @@ -92,8 +91,7 @@ const middlewares = [
next();
},

sapper({
manifest,
sapper.middleware({
store: (req, res) => {
return new Store({
title: `${req.hello} ${res.locals.name}`
Expand Down
4 changes: 2 additions & 2 deletions test/app/src/service-worker.js
Original file line number Diff line number Diff line change
@@ -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`;

// `shell` is an array of all the files generated by webpack,
// `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);

self.addEventListener('install', event => {
Expand Down
6 changes: 6 additions & 0 deletions test/app/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ module.exports = {
]
},
mode,
optimization: {
minimize: false
},
plugins: [
isDev && new webpack.HotModuleReplacementPlugin()
].filter(Boolean),
Expand Down Expand Up @@ -64,6 +67,9 @@ module.exports = {
]
},
mode,
optimization: {
minimize: false
},
performance: {
hints: false // it doesn't matter if server.js is large
}
Expand Down

0 comments on commit 5573258

Please sign in to comment.