aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/js/bun/http/node.js8
-rw-r--r--test/js/bun/http/sse-demo.ts33
-rw-r--r--test/js/bun/http/sse.test.ts16
3 files changed, 57 insertions, 0 deletions
diff --git a/test/js/bun/http/node.js b/test/js/bun/http/node.js
new file mode 100644
index 000000000..0a1102098
--- /dev/null
+++ b/test/js/bun/http/node.js
@@ -0,0 +1,8 @@
+// import { createServer } from "http";
+
+// const s = createServer((req, res) => {
+// res.writeHead(200, { "Content-Type": "bruh" });
+// res.end("bruh");
+// });
+
+// s.listen(3000, () => {});
diff --git a/test/js/bun/http/sse-demo.ts b/test/js/bun/http/sse-demo.ts
new file mode 100644
index 000000000..adec1420b
--- /dev/null
+++ b/test/js/bun/http/sse-demo.ts
@@ -0,0 +1,33 @@
+import { EventStream, serve } from "bun";
+
+serve({
+ port: 3000,
+ fetch(req) {
+ return new Response(
+ new EventStream({
+ start(controller) {
+ setTimeout(() => {
+ controller.send("hi");
+ // controller.close();
+ }, 1000);
+ },
+ cancel() {
+ console.log("CANCEL");
+ },
+ }),
+ {
+ headers: {
+ "Content-Bruh": "text/bruh",
+ "Content-Length": "452",
+ },
+ },
+ );
+ },
+});
+
+// // serve({
+// // port: 3000,
+// // fetch(req) {
+// // return new Response(new Blob(["hello world"], { type: "custom/type" }));
+// // },
+// // });
diff --git a/test/js/bun/http/sse.test.ts b/test/js/bun/http/sse.test.ts
new file mode 100644
index 000000000..470444ed4
--- /dev/null
+++ b/test/js/bun/http/sse.test.ts
@@ -0,0 +1,16 @@
+import { describe, test, jest } from "bun:test";
+
+test("aborted readable stream calls cancel", async () => {
+ const pull = jest.fn((ctrl: ReadableStreamDirectController) => {
+ console.log("fetch");
+ ctrl.write("hello");
+ ctrl.flush();
+ ctrl.write("hello");
+ ctrl.flush();
+ ctrl.write("hello");
+ ctrl.flush();
+ });
+ const cancel = jest.fn();
+
+ // server.stop();
+});