mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-15 20:34:44 +00:00
overhaul tests
This commit is contained in:
3
test/apps/export/src/routes/_error.html
Normal file
3
test/apps/export/src/routes/_error.html
Normal file
@@ -0,0 +1,3 @@
|
||||
<h1>{status}</h1>
|
||||
|
||||
<p>{error.message}</p>
|
||||
11
test/apps/export/src/routes/blog/[slug].html
Normal file
11
test/apps/export/src/routes/blog/[slug].html
Normal file
@@ -0,0 +1,11 @@
|
||||
<h1>{post.title}</h1>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
preload({ params }) {
|
||||
return this.fetch(`blog/${params.slug}.json`).then(r => r.json()).then(post => {
|
||||
return { post };
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
19
test/apps/export/src/routes/blog/[slug].json.js
Normal file
19
test/apps/export/src/routes/blog/[slug].json.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import posts from './_posts.js';
|
||||
|
||||
export function get(req, res) {
|
||||
const post = posts.find(post => post.slug === req.params.slug);
|
||||
|
||||
if (post) {
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
res.end(JSON.stringify(post));
|
||||
} else {
|
||||
res.writeHead(404, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
res.end(JSON.stringify({ message: 'not found' }));
|
||||
}
|
||||
}
|
||||
5
test/apps/export/src/routes/blog/_posts.js
Normal file
5
test/apps/export/src/routes/blog/_posts.js
Normal file
@@ -0,0 +1,5 @@
|
||||
export default [
|
||||
{ slug: 'foo', title: 'once upon a foo' },
|
||||
{ slug: 'bar', title: 'a bar is born' },
|
||||
{ slug: 'baz', title: 'bazzily ever after' }
|
||||
];
|
||||
15
test/apps/export/src/routes/blog/index.html
Normal file
15
test/apps/export/src/routes/blog/index.html
Normal file
@@ -0,0 +1,15 @@
|
||||
<h1>blog</h1>
|
||||
|
||||
{#each posts as post}
|
||||
<p><a href="blog/{post.slug}">{post.title}</a></p>
|
||||
{/each}
|
||||
|
||||
<script>
|
||||
export default {
|
||||
preload() {
|
||||
return this.fetch('blog.json').then(r => r.json()).then(posts => {
|
||||
return { posts };
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
9
test/apps/export/src/routes/blog/index.json.js
Normal file
9
test/apps/export/src/routes/blog/index.json.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import posts from './_posts.js';
|
||||
|
||||
export function get(req, res) {
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
res.end(JSON.stringify(posts));
|
||||
}
|
||||
3
test/apps/export/src/routes/index.html
Normal file
3
test/apps/export/src/routes/index.html
Normal file
@@ -0,0 +1,3 @@
|
||||
<h1>Great success!</h1>
|
||||
|
||||
<a href="blog">blog</a>
|
||||
Reference in New Issue
Block a user