-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] handle undefined body on endpoint output (#1808)
- Loading branch information
1 parent
af1aa54
commit 34d2049
Showing
6 changed files
with
70 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sveltejs/kit': patch | ||
--- | ||
|
||
handle undefined body on endpoint output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/kit/test/apps/basics/src/routes/endpoint-output/_tests.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as assert from 'uvu/assert'; | ||
|
||
/** @type {import('test').TestMaker} */ | ||
export default function (test) { | ||
test('not ok on void endpoint', null, async ({ fetch }) => { | ||
const res = await fetch('/endpoint-output/empty', { method: 'DELETE' }); | ||
assert.equal(res.ok, false); | ||
}); | ||
test('200 status on empty endpoint', null, async ({ fetch }) => { | ||
const res = await fetch('/endpoint-output/empty'); | ||
assert.equal(res.status, 200); | ||
assert.equal(await res.json(), {}); | ||
}); | ||
|
||
test('set-cookie without body', null, async ({ fetch }) => { | ||
const res = await fetch('/endpoint-output/headers'); | ||
assert.equal(res.status, 200); | ||
assert.equal(res.headers.has('set-cookie'), true); | ||
}); | ||
|
||
test('200 status by default', null, async ({ fetch }) => { | ||
const res = await fetch('/endpoint-output/body'); | ||
assert.equal(res.status, 200); | ||
assert.equal(await res.text(), '{}'); | ||
}); | ||
|
||
test('does not throw on blob method', null, async ({ fetch }) => { | ||
const res = await fetch('/endpoint-output/empty'); | ||
assert.type(await res.blob(), 'object'); | ||
}); | ||
test('does not throw on arrayBuffer method', null, async ({ fetch }) => { | ||
const res = await fetch('/endpoint-output/empty'); | ||
assert.type(await res.arrayBuffer(), 'object'); | ||
}); | ||
test('does not throw on buffer method', null, async ({ fetch }) => { | ||
const res = await fetch('/endpoint-output/empty'); | ||
assert.type(await res.buffer(), 'object'); | ||
}); | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/kit/test/apps/basics/src/routes/endpoint-output/body.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** @type {import('@sveltejs/kit').RequestHandler} */ | ||
export function get() { | ||
return { body: {} }; | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/kit/test/apps/basics/src/routes/endpoint-output/empty.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** @type {import('@sveltejs/kit').RequestHandler} */ | ||
export function get() { | ||
return {}; | ||
} | ||
|
||
/** @type {import('@sveltejs/kit').RequestHandler} */ | ||
export function del() {} |
8 changes: 8 additions & 0 deletions
8
packages/kit/test/apps/basics/src/routes/endpoint-output/headers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** @type {import('@sveltejs/kit').RequestHandler} */ | ||
export function get() { | ||
return { | ||
headers: { | ||
'Set-Cookie': 'foo=bar' | ||
} | ||
}; | ||
} |