Skip to content

Commit

Permalink
Add regression test for broken body (#3346)
Browse files Browse the repository at this point in the history
Signed-off-by: Matteo Collina <[email protected]>
  • Loading branch information
mcollina authored Jun 19, 2024
1 parent e5c242d commit 9134ee6
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/fetch/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,21 @@ test('constructing a Response with a ReadableStream body', async (t) => {
assert.deepStrictEqual(await response3.json(), JSON.parse(text))
})

await t.test('.arrayBuffer() correctly clones multiple buffers', async () => {
const buffer = Buffer.allocUnsafeSlow(2 * 1024 - 2)
const readable = new ReadableStream({
start (controller) {
for (let i = 0; i < buffer.length; i += 128) {
controller.enqueue(buffer.slice(i, i + 128))
}
controller.close()
}
})

const response = new Response(readable)
assert.deepStrictEqual(await response.arrayBuffer(), buffer.buffer)
})

await t.test('Readable stream with non-Uint8Array chunks', async () => {
const readable = new ReadableStream({
start (controller) {
Expand Down

0 comments on commit 9134ee6

Please sign in to comment.