Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
status: 200,
headers: { contentType: 'application/json' },
body: `{"witaj": "swiecie", "${remoteVersion}": 777}`
}, {name: 'reconnect'});
// wait for HTTP responses and WebSocket server to be established
await sleep();
// issue a change that will not get acknoledged by server
palindrom.obj.hello = 'OT';
// close the WS
mockSocketServer.close({
code,
wasClean,
reason
});
// setup another web socket so reconnection would not throw an error
anotherSocket = new MockSocketServer(getTestURL('testURL', false, true));
});
if(!wasClean && !reason){
describe('mapboxgl_DataFlowService', () => {
var originalTimeout;
var service;
var mockServer = new Server(urlDataFlow);
beforeAll(() => {
var e = {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [0, 0]
},
"properties": {
"id": 1
}
};
mockServer.on('connection', socket => {
socket.on('message', () => {
console.log("onmessage");
});
socket.on('close', () => { });
beforeEach(() => {
if (mockServer) {
mockServer.stop()
}
pongMock = jest.fn(data => {
if (data === 'ping') {
mockServer.emit('pong', true)
}
})
mockServer = new Server(host)
mockServer.on('connection', socket => {
mockServer.emit('data', 'test')
socket.on('message', pongMock)
})
mockServer.on('message', socket => {
mockServer.emit('data', 'test')
})
const routeCallbacks = []
routerNext = jest.fn()
router = {
beforeEach: jest.fn(callback => {
routeCallbacks.push(callback)
}),
push () {
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);
});
beforeEach(async () => {
mockSocketServer = new MockSocketServer(getTestURL('testURL', false, true));
fetchMock.get(getTestURL('testURL'), {
status: 200,
headers: { contentType: 'application/json' },
body: '{"hello": "world"}'
}, {name: 'establish'});
onReconnectionCountdown = sinon.spy();
onReconnectionEnd = sinon.spy();
palindrom = new Palindrom({
remoteUrl: getTestURL('testURL'),
ot: true,
localVersionPath,
remoteVersionPath,
onReconnectionCountdown,
onReconnectionEnd,
useWebSocket: true,
before(function () {
const fakeURL = 'ws://localhost:8080/peerjs?key=peerjs&id=1&token=testToken';
mockServer = new Server(fakeURL);
mockServer.on('connection', socket => {
//@ts-ignore
socket.on('message', data => {
socket.send('test message from mock server');
});
socket.send(ServerMessageType.Open);
});
});
function initServer(): void {
if (mockServer) {
mockServer.close();
mockServerWebSocket = undefined;
}
mockServer = new Server(
server,
{ selectProtocol: (protocols: Array) => "sip" }
);
mockServer.on("connection", (socket) => {
logger.log("Mock WebSocket Server: incoming connection");
mockServerWebSocket = socket;
socket.on("message", (receivedMessage) => {
if (typeof receivedMessage !== "string") {
throw new Error("Mock WebSocket Server received message not of type string.");
}
logger.log(`Mock WebSocket Server: received message "${receivedMessage}"`);
mockServerReceivedMessage = receivedMessage;
});
socket.on("close", () => {
beforeEach(() => {
server = new Server("ws://localhost:8000")
socket = new WebSocket("ws://localhost:8000")
transport = new WebSocketTransport(socket)
subscriber = jest.fn()
})
beforeEach(() => {
mockServer = new Server(url);
});
function createMockServer(host: string) {
const wsHost = setWsProtocol(host);
return new Server(wsHost);
}