How to use the mock-socket.WebSocket function in mock-socket

To help you get started, we’ve selected a few mock-socket examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github logdna / logdna-agent / test / lib / windows-utilities.js View on Github external
it('streams event logs to a socket', function() {
            this.timeout(100000);
            const MockWebSocket = require('mock-socket').WebSocket;
            const MockServer = require('mock-socket').Server;
            var server = new MockServer('ws://localhost:40002');
            var socket = new MockWebSocket('ws://localhost:40002');
            socket.connected = true;
            var lineBuffer = require('../../lib/linebuffer');
            lineBuffer.setSocket(socket);
            var windowsUtilities = requireUncached('../../lib/windows-utilities');

            return new Promise((resolve) => {
                server.on('message', data => {
                    debug('received message!');
                    debug(data);
                    var message = JSON.parse(data);
                    var line = message.ls[0].l;
                    assert.equal(JSON.parse(line).Message, 'arbitraryData');
                    resolve(true);
                });

                setInterval(() => {
github nathantsoi / vue-native-websocket / test / unit / specs / Observer.spec.js View on Github external
commit: () => {},
        dispatch: () => {}
    })
    mockStore.expects('dispatch').withArgs(expectedMsg.namespace + '/' + expectedMsg.action, expectedMsg)

    mockServer = new Server(wsUrl)
    mockServer.on('connection', ws => {
      ws.send(JSON.stringify(expectedMsg))
    })

    Vue.use(VueNativeSock, wsUrl)
    let vm = new Vue()
    observer = new Observer(wsUrl, {
      store: mockStore.object,
      format: 'json',
      websocket: new WebSocket(wsUrl)
    })

    setTimeout(() => {
      mockStore.verify()
      mockServer.stop(done)
    }, 100)
  })
github nathantsoi / vue-native-websocket / test / unit / specs / Observer.spec.js View on Github external
beforeEach(() => {
      mockServer = new Server(wsUrl)
      mockServer.on('connection', ws => ws.send('hi'))
      Vue.use(VueNativeSock, wsUrl)
      vm = new Vue()
      mockStore = sinon.mock({ commit: () => {} })

      observer = new Observer(wsUrl, {
        store: mockStore.object,
        reconnection: true,
        reconnectionAttempts: 2,
        WebSocket: new WebSocket(wsUrl),
      })
    })
github axisgroup / RxQ / test / util / mock-qix-engine.js View on Github external
function mockEngine() {
  var stamp = Date.now();
  var url = `ws://127.0.0.1:4848/${stamp}`;
  const server = new Server(url);
  const ws = new WebSocket(url);

  server.on("message", msg => {
    const { id, method } = JSON.parse(msg);

    server.send(
      JSON.stringify({
        jsonrpc: "2.0",
        id: id,
        result: {
          foo: "bar",
          method
        }
      })
    );
  });
github local-group-games / web-udp / packages / protocol / src / transport / socket.spec.js View on Github external
beforeEach(() => {
    server = new Server("ws://localhost:8000")
    socket = new WebSocket("ws://localhost:8000")
    transport = new WebSocketTransport(socket)
    subscriber = jest.fn()
  })

mock-socket

Javascript mocking library for websockets and socket.io

MIT
Latest version published 1 year ago

Package Health Score

63 / 100
Full package analysis