Permalink
Browse files

Test attaching `WebSocketServer` to a HTTP server

  • Loading branch information...
1 parent 0380d69 commit 11af5beb4f14918596779ef235ce715c0d7d123a @mmalecki committed Dec 14, 2011
Showing with 19 additions and 0 deletions.
  1. +19 −0 test/WebSocketServer.test.js
@@ -1,4 +1,5 @@
var assert = require('assert')
+ , http = require('http')
, WebSocket = require('../')
, WebSocketServer = WebSocket.Server
, fs = require('fs');
@@ -49,6 +50,11 @@ describe('WebSocketServer', function() {
var wss = new WebSocketServer({port: 1});
wss.on('error', function() { done(); })
})
+ it('uses passed server object', function () {
+ var srv = http.createServer()
+ , wss = new WebSocketServer({server: srv});
+ wss._server.should.equal(srv);
+ });
})
describe('#close', function() {
@@ -79,6 +85,19 @@ describe('WebSocketServer', function() {
});
})
+ it('works with a http server', function (done) {
+ var srv = http.createServer();
+ srv.listen(++port, function () {
+ var wss = new WebSocketServer({server: srv});
+ var ws = new WebSocket('ws://localhost:' + port);
+
+ wss.on('connection', function(client) {
+ wss.close();
+ done();
+ });
+ });
+ })
+
it('can send data', function(done) {
var wss = new WebSocketServer({port: ++port}, function() {
var ws = new WebSocket('ws://localhost:' + port);

0 comments on commit 11af5be

Please sign in to comment.