Skip to content

Commit

Permalink
fix: remove unreachable code
Browse files Browse the repository at this point in the history
  • Loading branch information
sirenkovladd committed Sep 20, 2024
1 parent d45e5cd commit 243150b
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
1 change: 0 additions & 1 deletion .node-version

This file was deleted.

2 changes: 1 addition & 1 deletion __tests__/application/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('app', () => {

it('should set compose from the constructor', () => {
const compose = () => (ctx) => {}
const app = new Koa({ compose })
const app = new Koa.default({ compose })
assert.strictEqual(app.compose, compose)
})

Expand Down
19 changes: 17 additions & 2 deletions __tests__/application/respond.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,20 @@ describe('app.respond', () => {
.expect(200)
.expect('content-type', 'application/octet-stream')
})

it('should respond hello', async () => {
const app = new Koa()

app.use(async ctx => {
ctx.body = new Blob(['hello']).stream()
})

return request(app.callback())
.get('/')
.expect(200)
.expect('content-type', 'application/octet-stream')
.expect(Buffer.from('hello'))
})
})

describe('when .body is a Response', () => {
Expand All @@ -578,13 +592,14 @@ describe('app.respond', () => {

app.use(ctx => {
ctx.body = new Response(null, { status: 200, statusText: 'OK' })
console.log(ctx)
})

return request(app.callback())
.head('/')
.get('/')
.expect(200)
.expect('content-type', 'application/octet-stream')
.expect('content-length', '2')
.expect(Buffer.from([]))
})
})

Expand Down
2 changes: 1 addition & 1 deletion lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ function respond (ctx) {
if (body instanceof Stream) return body.pipe(res)
if (body instanceof Blob) return Stream.Readable.from(body.stream()).pipe(res)
if (body instanceof ReadableStream) return Stream.Readable.from(body).pipe(res)
if (body instanceof Response) return Stream.Readable.from(body?.body).pipe(res)
if (body instanceof Response) return Stream.Readable.from(body?.body || '').pipe(res)

// body: json
body = JSON.stringify(body)
Expand Down
2 changes: 0 additions & 2 deletions lib/only.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
module.exports = (obj, keys) => {
obj = obj || {}
if (typeof keys === 'string') keys = keys.split(/ +/)
const ret = {}
for (let i = 0; i < keys.length; i++) {
const key = keys[i]
Expand Down
3 changes: 0 additions & 3 deletions lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,6 @@ module.exports = {
this.set(key, headers.get(key))
}

if (val.redirected) {
this.redirect(val.url)
}
return
}

Expand Down

0 comments on commit 243150b

Please sign in to comment.