Skip to content

Commit

Permalink
first socket.io test is passing
Browse files Browse the repository at this point in the history
  • Loading branch information
dmcaulay committed May 15, 2012
1 parent 12ecff1 commit b06773b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
11 changes: 11 additions & 0 deletions lib/chat.js
@@ -0,0 +1,11 @@
var io = require('socket.io');

module.exports = function(app) {
var server = io.listen(app);
server.sockets.on('connection', function(socket) {
socket.on('joined', function(data) {
socket.broadcast.emit('joined', data);
});
});
};

10 changes: 5 additions & 5 deletions test/chat-test.js
Expand Up @@ -3,11 +3,11 @@ var io = require('socket.io-client')
, chat = require('../lib/chat');

describe('chat', function() {
var port = 8081;
it('notifies the users when someone joins the chat') {
var port = 8888;
it('notifies the users when someone joins the chat', function(done) {
var server = chat(port);
var joe = io.connect('http://localhost:' + port);
var jon = io.connect('http://localhost:' + port);
var joe = io.connect('http://localhost:' + port, {'force new connection': true});
var jon = io.connect('http://localhost:' + port, {'force new connection': true});

// we're done after joe and jon are both notified
var notification = 0;
Expand All @@ -19,7 +19,7 @@ describe('chat', function() {

joe.on('joined', joined);
jon.on('joined', joined);
var jane = io.connect('http://localhost:' + port);
var jane = io.connect('http://localhost:' + port, {'force new connection': true});
jane.emit('joined', {username: 'jane'});
});
});

0 comments on commit b06773b

Please sign in to comment.