UNPKG

@lesy/lesy-plugin-pilot

Version:

38 lines (37 loc) 1.27 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const ws_1 = __importDefault(require("ws")); const pilot_socket_1 = require("../pilot.socket"); describe("web socket", () => { let wsServer; let wsClient; beforeAll((done) => { wsServer = new pilot_socket_1.WebSocketBus().startServer("localhost", 1234).init({ requestRunCommand: (payload) => { return { success: true, data: payload, }; }, }); wsServer["ws"].on("connection", () => wsClient.on("open", done)); wsClient = new ws_1.default(`ws://localhost:1234`); }); afterAll((done) => { wsClient.close(); wsServer.close(done); }); it("should exchange messages", (done) => { wsClient.on("message", (m) => { expect(m).toEqual(JSON.stringify({ success: true, data: "echo 123", })); done(); }); wsClient.send(JSON.stringify({ REQUEST: "requestRunCommand", PAYLOAD: "echo 123" })); }); });