From 54dfbdf987644fda3d795d298e3369cacf6de7f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20F=2E=20Romaniello?= Date: Fri, 29 May 2015 09:39:49 -0300 Subject: [PATCH] improve tests --- test/authorizer.test.js | 4 ++++ test/authorizer_noqs.test.js | 11 ++++++----- test/fixture/index.js | 11 +++++++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/test/authorizer.test.js b/test/authorizer.test.js index 5c868f2..3e2efc3 100644 --- a/test/authorizer.test.js +++ b/test/authorizer.test.js @@ -18,6 +18,7 @@ describe('authorizer', function () { socket.on('error', function(err){ err.message.should.eql("jwt malformed"); err.code.should.eql("invalid_token"); + socket.close(); done(); }); }); @@ -43,6 +44,7 @@ describe('authorizer', function () { 'query': 'token=' + this.token }); socket.on('connect', function(){ + socket.close(); done(); }).on('error', done); }); @@ -59,8 +61,10 @@ describe('authorizer', function () { 'query': 'token=' + this.token }); socket.on('connect', function () { + socket.close(); done(new Error('this shouldnt happen')); }).on('error', function (err) { + socket.close(); err.message.should.eql("jwt signature is required"); done(); }); diff --git a/test/authorizer_noqs.test.js b/test/authorizer_noqs.test.js index 5ad39fe..ed49a1d 100644 --- a/test/authorizer_noqs.test.js +++ b/test/authorizer_noqs.test.js @@ -55,11 +55,12 @@ describe('authorizer without querystring', function () { }); var token = this.token; socket.on('connect', function(){ - console.log('connected'); - socket.on('echo-response', done) - .on('authenticated', function () { - socket.emit('echo'); - }).emit('authenticate', { token: token }); + socket.on('echo-response', function () { + socket.close(); + done(); + }).on('authenticated', function () { + socket.emit('echo'); + }).emit('authenticate', { token: token }); }); }); }); diff --git a/test/fixture/index.js b/test/fixture/index.js index 070219a..126514e 100644 --- a/test/fixture/index.js +++ b/test/fixture/index.js @@ -8,7 +8,7 @@ var jwt = require('jsonwebtoken'); var xtend = require('xtend'); -var server; +var server, sio; exports.start = function (options, callback) { @@ -46,13 +46,12 @@ exports.start = function (options, callback) { server = http.createServer(app); - var sio = socketIo.listen(server); + sio = socketIo.listen(server); if (options.handshake) { // this.set('authorization', socketio_jwt.authorize(options)); sio.use(socketio_jwt.authorize(options)); } - sio.set('log level', 0); if (options.handshake) { sio.sockets.on('echo', function (m) { @@ -68,10 +67,14 @@ exports.start = function (options, callback) { }); } + server.__sockets = []; + server.on('connection', function (c) { + server.__sockets.push(c); + }); server.listen(9000, callback); }; exports.stop = function (callback) { - server.close(); + sio.close(); callback(); }; \ No newline at end of file