aboutsummaryrefslogtreecommitdiff
path: root/integration/bunjs-only-snippets/websocket.test.js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-06-22 23:21:48 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-06-22 23:21:48 -0700
commit729d445b6885f69dd2c6355f38707bd42851c791 (patch)
treef87a7c408929ea3f57bbb7ace380cf869da83c0e /integration/bunjs-only-snippets/websocket.test.js
parent25f820c6bf1d8ec6d444ef579cc036b8c0607b75 (diff)
downloadbun-729d445b6885f69dd2c6355f38707bd42851c791.tar.gz
bun-729d445b6885f69dd2c6355f38707bd42851c791.tar.zst
bun-729d445b6885f69dd2c6355f38707bd42851c791.zip
change the directory structurejarred/rename
Diffstat (limited to 'integration/bunjs-only-snippets/websocket.test.js')
-rw-r--r--integration/bunjs-only-snippets/websocket.test.js79
1 files changed, 0 insertions, 79 deletions
diff --git a/integration/bunjs-only-snippets/websocket.test.js b/integration/bunjs-only-snippets/websocket.test.js
deleted file mode 100644
index ab825fa63..000000000
--- a/integration/bunjs-only-snippets/websocket.test.js
+++ /dev/null
@@ -1,79 +0,0 @@
-import { describe, it, expect } from "bun:test";
-import { unsafe } from "bun";
-import { gc } from "./gc";
-
-const TEST_WEBSOCKET_HOST =
- process.env.TEST_WEBSOCKET_HOST || "wss://ws.postman-echo.com/raw";
-
-describe("WebSocket", () => {
- it("should connect", async () => {
- const ws = new WebSocket(TEST_WEBSOCKET_HOST);
- await new Promise((resolve, reject) => {
- ws.onopen = resolve;
- ws.onerror = reject;
- });
- var closed = new Promise((resolve, reject) => {
- ws.onclose = resolve;
- });
- ws.close();
- await closed;
- });
-
- it("should send and receive messages", async () => {
- const ws = new WebSocket(TEST_WEBSOCKET_HOST);
- await new Promise((resolve, reject) => {
- ws.onopen = resolve;
- ws.onerror = reject;
- ws.onclose = () => {
- reject("WebSocket closed");
- };
- });
- const count = 10;
-
- // 10 messages in burst
- var promise = new Promise((resolve, reject) => {
- var remain = count;
- ws.onmessage = (event) => {
- gc(true);
- expect(event.data).toBe("Hello World!");
- remain--;
-
- if (remain <= 0) {
- ws.onmessage = () => {};
- resolve();
- }
- };
- ws.onerror = reject;
- });
-
- for (let i = 0; i < count; i++) {
- ws.send("Hello World!");
- gc(true);
- }
-
- await promise;
- var echo = 0;
-
- // 10 messages one at a time
- function waitForEcho() {
- return new Promise((resolve, reject) => {
- gc(true);
- const msg = `Hello World! ${echo++}`;
- ws.onmessage = (event) => {
- expect(event.data).toBe(msg);
- resolve();
- };
- ws.onerror = reject;
- ws.onclose = reject;
- ws.send(msg);
- gc(true);
- });
- }
- gc(true);
- for (let i = 0; i < count; i++) await waitForEcho();
- ws.onclose = () => {};
- ws.onerror = () => {};
- ws.close();
- gc(true);
- });
-});