diff options
author | 2022-06-09 21:29:57 -0700 | |
---|---|---|
committer | 2022-06-09 21:29:57 -0700 | |
commit | 5ccf606107b045ad32e2eed8d1c757b30a6e4040 (patch) | |
tree | 3839b85ef4089e3327018c0fa6737458ba00a5e5 /integration/bunjs-only-snippets | |
parent | b8eea5cc4a1f9b6dd1a6a08d531e8e096c60cb5b (diff) | |
download | bun-5ccf606107b045ad32e2eed8d1c757b30a6e4040.tar.gz bun-5ccf606107b045ad32e2eed8d1c757b30a6e4040.tar.zst bun-5ccf606107b045ad32e2eed8d1c757b30a6e4040.zip |
`new Response(stream).arrayBuffer()` + 3 more
- `new Response(stream).arrayBuffer()`
- `new Response(stream).json()`
- `new Response(stream).text()`
- `new Response(stream).blob()`
Diffstat (limited to 'integration/bunjs-only-snippets')
-rw-r--r-- | integration/bunjs-only-snippets/bun-jsc.test.js | 2 | ||||
-rw-r--r-- | integration/bunjs-only-snippets/concat.test.js | 4 | ||||
-rw-r--r-- | integration/bunjs-only-snippets/inspect.test.js | 1 | ||||
-rw-r--r-- | integration/bunjs-only-snippets/streams.test.js | 93 | ||||
-rw-r--r-- | integration/bunjs-only-snippets/transpiler.test.js | 7 |
5 files changed, 99 insertions, 8 deletions
diff --git a/integration/bunjs-only-snippets/bun-jsc.test.js b/integration/bunjs-only-snippets/bun-jsc.test.js index e329bc092..975003b77 100644 --- a/integration/bunjs-only-snippets/bun-jsc.test.js +++ b/integration/bunjs-only-snippets/bun-jsc.test.js @@ -77,7 +77,7 @@ describe("bun:jsc", () => { count(); }); it("numberOfDFGCompiles", () => { - expect(numberOfDFGCompiles(count)).toBe(3); + expect(numberOfDFGCompiles(count) > 0).toBe(true); }); it("releaseWeakRefs", () => { releaseWeakRefs(); diff --git a/integration/bunjs-only-snippets/concat.test.js b/integration/bunjs-only-snippets/concat.test.js index 9f3e1f257..a965fdb94 100644 --- a/integration/bunjs-only-snippets/concat.test.js +++ b/integration/bunjs-only-snippets/concat.test.js @@ -1,6 +1,6 @@ import { describe, it, expect } from "bun:test"; import { gcTick } from "./gc"; -import { concat } from "bun"; +import { concatArrayBuffers } from "bun"; describe("concat", () => { function polyfill(chunks) { @@ -19,7 +19,7 @@ describe("concat", () => { } function concatToString(chunks) { - return Array.from(new Uint8Array(concat(chunks))).join(""); + return Array.from(new Uint8Array(concatArrayBuffers(chunks))).join(""); } function polyfillToString(chunks) { diff --git a/integration/bunjs-only-snippets/inspect.test.js b/integration/bunjs-only-snippets/inspect.test.js index d110cd4b4..344fd7a78 100644 --- a/integration/bunjs-only-snippets/inspect.test.js +++ b/integration/bunjs-only-snippets/inspect.test.js @@ -91,4 +91,5 @@ it("inspect", () => { ).toBe(`<div hello="quoted"> <input type="text" value="123" /> </div>`); + expect(Bun.inspect(BigInt(32)), "32n"); }); diff --git a/integration/bunjs-only-snippets/streams.test.js b/integration/bunjs-only-snippets/streams.test.js index d694be1ba..a3d4965ee 100644 --- a/integration/bunjs-only-snippets/streams.test.js +++ b/integration/bunjs-only-snippets/streams.test.js @@ -184,3 +184,96 @@ it("ReadableStream for empty file closes immediately", async () => { expect(chunks.length).toBe(0); }); + +it("new Response(stream).arrayBuffer() (bytes)", async () => { + var queue = [Buffer.from("abdefgh")]; + var stream = new ReadableStream({ + pull(controller) { + var chunk = queue.shift(); + if (chunk) { + controller.enqueue(chunk); + } else { + controller.close(); + } + }, + cancel() {}, + type: "bytes", + }); + const buffer = await new Response(stream).arrayBuffer(); + expect(new TextDecoder().decode(new Uint8Array(buffer))).toBe("abdefgh"); +}); + +it("new Response(stream).arrayBuffer() (default)", async () => { + var queue = [Buffer.from("abdefgh")]; + var stream = new ReadableStream({ + pull(controller) { + var chunk = queue.shift(); + if (chunk) { + controller.enqueue(chunk); + } else { + controller.close(); + } + }, + cancel() {}, + }); + const buffer = await new Response(stream).arrayBuffer(); + expect(new TextDecoder().decode(new Uint8Array(buffer))).toBe("abdefgh"); +}); + +it("new Response(stream).text() (default)", async () => { + var queue = [Buffer.from("abdefgh")]; + var stream = new ReadableStream({ + pull(controller) { + var chunk = queue.shift(); + if (chunk) { + controller.enqueue(chunk); + } else { + controller.close(); + } + }, + cancel() {}, + }); + const text = await new Response(stream).text(); + expect(text).toBe("abdefgh"); +}); + +it("new Response(stream).json() (default)", async () => { + var queue = [Buffer.from(JSON.stringify({ hello: true }))]; + var stream = new ReadableStream({ + pull(controller) { + var chunk = queue.shift(); + if (chunk) { + controller.enqueue(chunk); + } else { + controller.close(); + } + }, + cancel() {}, + }); + const json = await new Response(stream).json(); + expect(json.hello).toBe(true); +}); + +it("new Response(stream).blob() (default)", async () => { + var queue = [Buffer.from(JSON.stringify({ hello: true }))]; + var stream = new ReadableStream({ + pull(controller) { + var chunk = queue.shift(); + if (chunk) { + controller.enqueue(chunk); + } else { + controller.close(); + } + }, + cancel() {}, + }); + const blob = await new Response(stream).blob(); + expect(await blob.text()).toBe('{"hello":true}'); +}); + +it("Blob.stream() -> new Response(stream).text()", async () => { + var blob = new Blob(["abdefgh"]); + var stream = blob.stream(); + const text = await new Response(stream).text(); + expect(text).toBe("abdefgh"); +}); diff --git a/integration/bunjs-only-snippets/transpiler.test.js b/integration/bunjs-only-snippets/transpiler.test.js index 30fc2afde..f8da4c18c 100644 --- a/integration/bunjs-only-snippets/transpiler.test.js +++ b/integration/bunjs-only-snippets/transpiler.test.js @@ -358,12 +358,9 @@ export var ComponentThatChecksDefaultPropsAndHasChildren = { type: Hello, key: null, ref: null, - props: !Hello.defaultProps ? { + props: __merge({ children: "my child" - } : { - ...Hello.defaultProps, - children: "my child" - }, + }, Hello.defaultProps), _owner: null }; export var ComponentThatHasSpreadCausesDeopt = jsx(Hello, { |