Skip to content

Commit 28bd49f

Browse files
committed
add more tests, remove src changes
1 parent 0b87fc5 commit 28bd49f

File tree

7 files changed

+66
-5
lines changed

7 files changed

+66
-5
lines changed

packages/kit/src/runtime/server/page/respond.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,6 @@ export async function respond(opts) {
125125

126126
if (loaded.loaded.error) {
127127
({ status, error } = loaded.loaded);
128-
const e = coalesce_to_error(error);
129-
options.handle_error(e, event);
130128
}
131129
} catch (err) {
132130
const e = coalesce_to_error(err);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** @type {import('@sveltejs/kit').RequestHandler} */
2+
export function get() {
3+
return {
4+
status: 555
5+
};
6+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<script context="module">
2+
/** @type {import('@sveltejs/kit').Load} */
3+
export async function load({ fetch }) {
4+
const res = await fetch('/errors/endpoint-not-ok.json');
5+
if (res.ok) {
6+
return {
7+
props: await res.json()
8+
};
9+
} else {
10+
return {
11+
status: res.status,
12+
error: new Error(res.statusText)
13+
};
14+
}
15+
}
16+
</script>
17+
18+
<h1>this text should not appear</h1>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** @type {import('@sveltejs/kit').RequestHandler} */
2+
export function get() {
3+
return {
4+
status: 555
5+
};
6+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
<h1>this text should not appear</h1>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/** @type {import('@sveltejs/kit').RequestHandler} */
22
export function get() {
3-
throw new Error('nope shadow');
3+
throw new Error('nope');
44
}

packages/kit/test/apps/basics/test/test.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,24 @@ test.describe.parallel('Errors', () => {
764764
}
765765
});
766766

767+
test('not ok response from endpoint', async ({ page, read_errors }) => {
768+
const res = await page.goto('/errors/endpoint-not-ok');
769+
770+
expect(read_errors('/errors/endpoint-not-ok.json')).toBeUndefined();
771+
772+
expect(res && res.status()).toBe(555);
773+
expect(await page.textContent('#message')).toBe('This is your custom error page saying: ""');
774+
775+
const contents = await page.textContent('#stack');
776+
const location = 'endpoint-not-ok.svelte:12:15';
777+
778+
if (process.env.DEV) {
779+
expect(contents).toMatch(location);
780+
} else {
781+
expect(contents).not.toMatch(location);
782+
}
783+
});
784+
767785
test('error in shadow endpoint', async ({ page, read_errors }) => {
768786
const res = await page.goto('/errors/endpoint-shadow');
769787

@@ -776,10 +794,12 @@ test.describe.parallel('Errors', () => {
776794
}
777795

778796
expect(res && res.status()).toBe(500);
779-
expect(await page.textContent('#message')).toBe('This is your custom error page saying: ""');
797+
expect(await page.textContent('#message')).toBe(
798+
'This is your custom error page saying: "nope"'
799+
);
780800

781801
const contents = await page.textContent('#stack');
782-
const location = 'endpoint.svelte:12:15';
802+
const location = 'endpoint-shadow.js:1:8'; // TODO this is the wrong location, but i'm not going to open the sourcemap can of worms just now
783803

784804
if (process.env.DEV) {
785805
expect(contents).toMatch(location);
@@ -788,6 +808,17 @@ test.describe.parallel('Errors', () => {
788808
}
789809
});
790810

811+
test('not ok response from shadow endpoint', async ({ page, read_errors }) => {
812+
const res = await page.goto('/errors/endpoint-shadow-not-ok');
813+
814+
expect(read_errors('/errors/endpoint-shadow-not-ok')).toBeUndefined();
815+
816+
expect(res && res.status()).toBe(555);
817+
expect(await page.textContent('#message')).toBe(
818+
'This is your custom error page saying: "Failed to load data"'
819+
);
820+
});
821+
791822
test('server-side 4xx status without error from load()', async ({ page }) => {
792823
const response = await page.goto('/errors/load-status-without-error-server');
793824

0 commit comments

Comments
 (0)