forked from sebastienwindal/JScribble
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sebastien Windal
committed
Mar 30, 2013
1 parent
f1da560
commit 908484d
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,8 @@ | |
}, | ||
"engines": { | ||
"node": "0.8.x" | ||
}, | ||
"scripts": { | ||
"test": "expresso test/*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") | ||
}); | ||
}; | ||
|