Skip to content

Commit

Permalink
added expresso unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien Windal committed Mar 30, 2013
1 parent f1da560 commit 908484d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
},
"engines": {
"node": "0.8.x"
},
"scripts": {
"test": "expresso test/*"
}
}
48 changes: 48 additions & 0 deletions test/join.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

var assert = require('assert');
var express = require('express');

exports.testAsync = function(beforeExit) {
var io = require('socket.io-client');
var socket = io.connect('http://localhost:5000');

assert(socket !== null);
assert(socket !== undefined);
var wasConnected = false;
var timeout;
socket.on('connect', function(err) {
wasConnected = true;
assert.isUndefined(err);

// send the join message...
socket.emit('join', JSON.stringify({ userName: 'testusername', userId: '1234', avatar: 'someImage.png' }));

// disconnect if no answer in 1/2 sec.
timeout = setTimeout(function() {
socket.disconnect();
}, 1000);
});

var connectResponseRecvd = false;

socket.on('chat', function(data) {
connectResponseRecvd = true;
clearTimeout(timeout);

var msg = JSON.parse(data);
assert(msg.action == 'control');
assert(msg.userId = '1234');
assert(msg.avatar == 'someImage.png');
assert(msg.userName == 'testusername');

socket.disconnect();
});

beforeExit(function(){
console.log("exit");
socket.disconnect();
assert(wasConnected, "socket.io never connected to server.");
assert(connectResponseRecvd, "No response to connect message.")
});
};

0 comments on commit 908484d

Please sign in to comment.