PageRenderTime 8ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/node-websocket-client/test/test-ready-state.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 23 lines | 17 code | 5 blank | 1 comment | 1 complexity | e26c2bd95bfc277c4ad5780764711728 MD5 | raw file
 1// Verify that readyState transitions are implemented correctly
 2
 3var assert = require('assert');
 4var WebSocket = require('../lib/websocket').WebSocket;
 5var WebSocketServer = require('websocket-server/ws').Server;
 6
 7var PORT = 1024 + Math.floor(Math.random() * 4096);
 8
 9var wss = new WebSocketServer();
10wss.listen(PORT, 'localhost');
11
12var ws = new WebSocket('ws://localhost:' + PORT);
13assert.equal(ws.readyState, ws.CONNECTING);
14ws.onopen = function() {
15    assert.equal(ws.readyState, ws.OPEN);
16
17    ws.close();
18    assert.ok(ws.readyState == ws.CLOSING);
19};
20ws.onclose = function() {
21    assert.equal(ws.readyState, ws.CLOSED);
22    wss.close();
23};