mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
Signed-off-by: npub1mprnacetjua2xx3p5eddmhxyk6wv929ymm5py8kd2xfxurxahspqqlgyta <d8473ee32b973aa31a21a65adddcc4b69cc2a8a4dee8121ecd51926e0cddbc02@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub1mprnacetjua2xx3p5eddmhxyk6wv929ymm5py8kd2xfxurxahspqqlgyta <d8473ee32b973aa31a21a65adddcc4b69cc2a8a4dee8121ecd51926e0cddbc02@sprout-oss.stage.blox.sqprod.co>
30 lines
943 B
JavaScript
30 lines
943 B
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import { closeAllWebSockets, closeWebSocket } from "./relayWebSocketClose.ts";
|
|
|
|
test("closeWebSocket invokes authoritative native disconnect", async () => {
|
|
const calls = [];
|
|
await closeWebSocket(42, "community switch", async (cmd, args) => {
|
|
calls.push({ cmd, args });
|
|
});
|
|
|
|
assert.deepEqual(calls, [
|
|
{ cmd: "plugin:websocket|disconnect", args: { id: 42 } },
|
|
]);
|
|
});
|
|
|
|
test("closeWebSocket is idempotent when the native socket is gone", async () => {
|
|
await closeWebSocket(7, "connection reset", async () => {
|
|
throw new Error("WebSocket connection not found");
|
|
});
|
|
});
|
|
|
|
test("closeAllWebSockets invokes native process-wide teardown", async () => {
|
|
const calls = [];
|
|
await closeAllWebSockets(async (cmd, args) => calls.push({ cmd, args }));
|
|
assert.deepEqual(calls, [
|
|
{ cmd: "plugin:websocket|disconnect_all", args: undefined },
|
|
]);
|
|
});
|