🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

ws-mock

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ws-mock

Node module for mocking Web Socket (server side)

0.1.0
latest
Source
npm
Version published
Weekly downloads
73
2.82%
Maintainers
1
Weekly downloads
 
Created
Source

ws-mock

Node module for mocking Web Socket (server side). Can be very helpful if you want to test ws-dependent code.

Usage

First install via npm:

  • npm: npm install ws-mock

simple example:

  var WsServerMock = require('ws-mock').WsServer;
  // create ws server instance
  var wsServer = new WsServerMock();
  // bind events
  wsServer.on('connection', function (ws) {
  	console.log("new connection...");
  	ws.on('message', function (msg) {
  		console.log("incoming message:", msg);
  	});
  	ws.on('close', function () {
  		console.log("connection closed...");
  	});
  });
  // create ws connection 
  var wsConn = wsServer.addConnection(); // "new connection..."
  // send message that will be received by wsServer  
  wsConn.sendMsgToServer("dummy message"); // "incoming message: dummy message"
  // close a ws connection
  wsConn.closeConnection(); // "connection closed..."
  
  // clear all current connections
  wsServer.clearConnections();

Keywords

ws-mock

FAQs

Package last updated on 08 Jun 2019

Did you know?

Socket

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.

Install

Related posts