Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed existing tests #19

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
fix: merged upstream master with test/app
aarontravass committed Jun 29, 2023
commit 2a10b396592e64d5756f8a312d94852d8c8092d5
20 changes: 6 additions & 14 deletions extensions/res/send/send.ts
Original file line number Diff line number Diff line change
@@ -13,11 +13,11 @@ export const send = <
>(req: Req, res: Res) =>
async (body: unknown) => {
let bodyToSend = body
// in case of object - turn it to json

if (ArrayBuffer.isView(body)) {
body = bodyToSend
} else if (typeof bodyToSend === 'object' && bodyToSend !== null) {
if (isBuffer(body)) {
bodyToSend = body
} else if (typeof body === 'object' && body !== null) {
// in case of object - turn it to json
bodyToSend = JSON.stringify(body, null, 2)
res._init.headers?.set('Content-Type', 'application/json')
} else if (typeof body === 'string') {
@@ -64,16 +64,8 @@ async (body: unknown) => {
if (!res._init.headers.get('Content-Type')) {
res._init.headers.set('content-type', 'application/octet-stream')
}
return end(res)(bodyToSend)
} else {
return json(res)(bodyToSend)
}
} else {
if (typeof bodyToSend !== 'string' && bodyToSend) {
bodyToSend = (bodyToSend as string).toString()
}

return end(res)(bodyToSend as BodyInit)
return end(res)(bodyToSend as BodyInit)
} else return json(res)(bodyToSend)
}
if (typeof bodyToSend !== 'string') {
bodyToSend = (bodyToSend as string).toString()
11 changes: 5 additions & 6 deletions tests/modules/send.test.ts
Original file line number Diff line number Diff line change
@@ -120,12 +120,11 @@ describe('send(body)', () => {
.expectHeader('Content-Type', null)
.expectHeader('Transfer-Encoding', null)
})
it.skip('should set Content-Type to application/octet-stream for buffers if the header hasn\'t been set before', async () => {
const app = runServer((req, res) =>
send(req, res)(
new TextEncoder().encode('Hello World'),
) as unknown as Response
)
it('should set Content-Type to application/octet-stream for buffers if the header hasn\'t been set before', async () => {
const app = runServer(async (req, res) => {
const r = await send(req, res)(te.encode('Hello World'))
return new Response(r._body, r._init)
})

const res = await makeFetch(app)('/')
res.expectHeader(
You are viewing a condensed version of this merge commit. You can view the full changes here.