mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-17 13:14:54 +00:00
overhaul tests
This commit is contained in:
3
test/apps/errors/src/routes/_error.html
Normal file
3
test/apps/errors/src/routes/_error.html
Normal file
@@ -0,0 +1,3 @@
|
||||
<h1>{status}</h1>
|
||||
|
||||
<p>{error.message}</p>
|
||||
19
test/apps/errors/src/routes/blog/[slug].html
Normal file
19
test/apps/errors/src/routes/blog/[slug].html
Normal file
@@ -0,0 +1,19 @@
|
||||
<h1>{post.title}</h1>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
preload({ params }) {
|
||||
const { slug } = params;
|
||||
|
||||
return this.fetch(`blog/${slug}.json`).then(r => {
|
||||
return r.json().then(data => {
|
||||
if (r.status !== 200) {
|
||||
this.error(r.status, data);
|
||||
}
|
||||
|
||||
return data;
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
9
test/apps/errors/src/routes/blog/[slug].json.js
Normal file
9
test/apps/errors/src/routes/blog/[slug].json.js
Normal file
@@ -0,0 +1,9 @@
|
||||
export function get(req, res) {
|
||||
res.writeHead(404, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
res.end(JSON.stringify({
|
||||
message: 'not found'
|
||||
}));
|
||||
}
|
||||
5
test/apps/errors/src/routes/index.html
Normal file
5
test/apps/errors/src/routes/index.html
Normal file
@@ -0,0 +1,5 @@
|
||||
<h1>root</h1>
|
||||
|
||||
<a href="nope">nope</a>
|
||||
<a href="blog/nope">blog/nope</a>
|
||||
<a href="throw">throw</a>
|
||||
4
test/apps/errors/src/routes/nope.json.js
Normal file
4
test/apps/errors/src/routes/nope.json.js
Normal file
@@ -0,0 +1,4 @@
|
||||
export function get(req, res) {
|
||||
res.writeHead(500);
|
||||
res.end('nope');
|
||||
}
|
||||
7
test/apps/errors/src/routes/throw.html
Normal file
7
test/apps/errors/src/routes/throw.html
Normal file
@@ -0,0 +1,7 @@
|
||||
<script>
|
||||
export default {
|
||||
preload() {
|
||||
throw new Error('nope');
|
||||
}
|
||||
};
|
||||
</script>
|
||||
3
test/apps/errors/src/routes/throw.json.js
Normal file
3
test/apps/errors/src/routes/throw.json.js
Normal file
@@ -0,0 +1,3 @@
|
||||
export function get(req, res) {
|
||||
throw new Error('oops');
|
||||
}
|
||||
Reference in New Issue
Block a user