Skip to content

Commit

Permalink
fix: concat body in res.end
Browse files Browse the repository at this point in the history
fixes: antongolub#26

- added a test to demonstrate how write and end are used together that should fail with the current code
- use the already bound write method to ensure that body is concatenated correctly
- this seemed like the quickest way to do this, as callback isn't used
  • Loading branch information
ErisDS committed Jan 25, 2022
1 parent 95c04ea commit ec47f38
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/js/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default class Response implements IResponse {
}
this.end = (chunk: IData, encoding?: ?string): IResponse => {
if (chunk) {
body = chunk
write(chunk, encoding)
}
this.emit('finish')
return this
Expand Down
8 changes: 8 additions & 0 deletions src/test/js/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,13 @@ describe('response', () => {
res.write()
expect(res.body).toBe('foobar')
})

it('write and end', () => {
const res = new Response()
res.write('foo')
res.write(Buffer.from('bar'))
res.end('!')
expect(res.body).toBe('foobar!')
})
})
})

0 comments on commit ec47f38

Please sign in to comment.