aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/bun.js')
-rw-r--r--test/bun.js/node-http.test.ts72
-rw-r--r--test/bun.js/string-decoder.test.js6
2 files changed, 77 insertions, 1 deletions
diff --git a/test/bun.js/node-http.test.ts b/test/bun.js/node-http.test.ts
new file mode 100644
index 000000000..24b3f1c85
--- /dev/null
+++ b/test/bun.js/node-http.test.ts
@@ -0,0 +1,72 @@
+import { describe, expect, it } from "bun:test";
+import { createServer } from "node:http";
+
+describe("node:http", () => {
+ describe("createServer", async () => {
+ it("hello world", async () => {
+ const server = createServer((req, res) => {
+ res.writeHead(200, { "Content-Type": "text/plain" });
+ res.end("Hello World");
+ });
+ server.listen(8123);
+
+ const res = await fetch("http://localhost:8123");
+ expect(await res.text()).toBe("Hello World");
+ server.close();
+ });
+
+ it("request & response body streaming (large)", async () => {
+ const bodyBlob = new Blob(["hello world", "hello world".repeat(9000)]);
+
+ const input = await bodyBlob.text();
+
+ const server = createServer((req, res) => {
+ res.writeHead(200, { "Content-Type": "text/plain" });
+ req.on("data", (chunk) => {
+ res.write(chunk);
+ });
+
+ req.on("end", () => {
+ res.end();
+ });
+ });
+ server.listen(8124);
+
+ const res = await fetch("http://localhost:8124", {
+ method: "POST",
+ body: bodyBlob,
+ });
+
+ const out = await res.text();
+ expect(out).toBe(input);
+ server.close();
+ });
+
+ it("request & response body streaming (small)", async () => {
+ const bodyBlob = new Blob(["hello world", "hello world".repeat(4)]);
+
+ const input = await bodyBlob.text();
+
+ const server = createServer((req, res) => {
+ res.writeHead(200, { "Content-Type": "text/plain" });
+ req.on("data", (chunk) => {
+ res.write(chunk);
+ });
+
+ req.on("end", () => {
+ res.end();
+ });
+ });
+ server.listen(8125);
+
+ const res = await fetch("http://localhost:8125", {
+ method: "POST",
+ body: bodyBlob,
+ });
+
+ const out = await res.text();
+ expect(out).toBe(input);
+ server.close();
+ });
+ });
+});
diff --git a/test/bun.js/string-decoder.test.js b/test/bun.js/string-decoder.test.js
index 4664cc388..a29577acc 100644
--- a/test/bun.js/string-decoder.test.js
+++ b/test/bun.js/string-decoder.test.js
@@ -1,5 +1,9 @@
import { expect, it } from "bun:test";
-import { StringDecoder } from "string_decoder";
+var { StringDecoder } = require("string_decoder");
+
+it("require('string_decoder')", () => {
+ expect(StringDecoder1).toBe(StringDecoder);
+});
it("StringDecoder-utf8", () => {
test("utf-8", Buffer.from("$", "utf-8"), "$");