
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
Websocket testing made easy. Even with weird emits. ;)
The motivation with this module is to provide a high-level abstraction for testing Websockets endpoints.
Install WsReq as an npm module and save it to your package.json file as a development dependency:
npm i -D wsreq
or
yarn add -D wsreq
Once installed it can now be referenced by simply calling require('wsreq');
You may pass and http.Server to wsreq and the websocket pass. It will bound the server to a ephemeral port so you need to keep track of ports.
WsReq works with any test framework, here are some examples with jest:
Response from emit event in the server.
const wsreq = require("wsreq");
const app = require("../your/path");
test("should respond with msg.", async () => {
const res_ = await wsreq(app, "/ws/path");
res_.emit("ping", data);
const res = await res_.on("pong");
expect(res).toEqual(data);
});
Response from http server emit event.
test("should respond with msg (using http). ", async () => {
// method: "get" | "post" | "put" | "delete";
const res_ = await wsreq(app, path);
const res = await res_.onWithHttp("ws-event", {
url: "/http/server/url",
method: "post",
body: { ...someData },
headers: { ...someHeaders },
});
expect(res).toEquals({ ...compareData });
});
Invalid http server url.
test("should fail with status code 404.", async () => {
// method: "get" | "post" | "put" | "delete";
const res_ = await wsreq(app, path);
const res = await res_
.onWithHttp("ws-event", {
url: "/invalid/http/server/url",
method: "get",
headers: { ...someHeaders },
})
.catch((e: Error) => {
return {
msg: e.message,
};
});
expect(res).toEquals({ msg: "Request failed with status code 404" });
});
Invalid websocket connection or path.
test("should fail with invalid ws connection.", async () => {
const res = await wsreq(app, "/invalid/ws/path").catch((e: Error) => {
return {
msg: e.message,
};
});
expect(res).toEqual({ msg: "Invalid WS connection." });
});
Invalid websocket event name.
test("should fail with invalid ws event.", async () => {
const res_ = await wsreq(app, "/ws/path");
res_.emit("ping", data);
const res = await res_.on("no-pong").catch((e: Error) => {
return {
msg: e.message,
};
});
expect(res).toEquals({ msg: "Invalid WS event." });
});
Emits a new event to the websocket server.
Adds a new event listener to the socket.
Adds a new event listener to the socket and makes a http request to force the emit event in http server. Use only if you want to test emits from APIs.
I just wrote it because I needed it. ;)
Inspired in SuperTest.
MIT
FAQs
Websocket request lib for testing.
We found that wsreq-t demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.