diff options
author | 2023-06-28 11:46:17 -0400 | |
---|---|---|
committer | 2023-06-29 23:40:38 -0400 | |
commit | bb697687467b33b47f16d33d2dc8dfcc6ccf7274 (patch) | |
tree | b8bbbdfbbf276d645765ba772399ddde4f1f3700 /test | |
parent | 9e2e3732127ea77803e87cc8768c9040d1717ca7 (diff) | |
download | bun-bb697687467b33b47f16d33d2dc8dfcc6ccf7274.tar.gz bun-bb697687467b33b47f16d33d2dc8dfcc6ccf7274.tar.zst bun-bb697687467b33b47f16d33d2dc8dfcc6ccf7274.zip |
stuff
Diffstat (limited to 'test')
-rw-r--r-- | test/js/bun/http/node.js | 8 | ||||
-rw-r--r-- | test/js/bun/http/sse-demo.ts | 33 | ||||
-rw-r--r-- | test/js/bun/http/sse.test.ts | 16 |
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(); +}); |