是否有可能与摩卡testingsocket.io应用程序

我有一个Node.js与Socket.io服务器。 所以我想用摩卡书写testing来改善发展。 我已经search了很多,find有关与Mochatestingsocket.io服务器的一切,我发现是所有http://liamkaufman.com/blog/2012/01/28/testing-socketio-with-mocha-should-and- socketio客户机/

但是在Mocha的testing目录下有服务器和testing,并且都是从Mocha开始的,当时我已经有了服务器并且只是想testing它。

所以我写了下面的代码:

var assert = require("assert"), should = require('should'), io = require('socket.io-client'), socketURL = 'http://localhost:3102', options ={ transports: ['websocket'], 'force new connection': true, 'reconnection delay' : 0, 'reopen delay' : 0 }; describe('Server', function(){ var socket; beforeEach(function(done) { // Setup console.log('Establishing connection'); socket = io.connect(socketURL, options); socket.on('connect', function() { console.log('worked...'); done(); }); }); ... it('should receive messages', function(done){ socket.on('message', function(data){ console.log('received'); done(); }); ... }) 

结果是:

Server Establishing connection 1) "before each" hook 0 passing (2s) 1 failing 1) Server "before each" hook: Error: timeout of 2000ms exceeded at null. (\npm\node_modules\mocha\lib\runnable.js:139:19) at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
Server Establishing connection 1) "before each" hook 0 passing (2s) 1 failing 1) Server "before each" hook: Error: timeout of 2000ms exceeded at null. (\npm\node_modules\mocha\lib\runnable.js:139:19) at Timer.listOnTimeout [as ontimeout] (timers.js:110:15) 

我已经检查过服务器的日志,没有任何连接。 它甚至没有尝试连接到服务器。

所以我想知道是否有可能以这种方式与摩卡一起进行testing? 当你有完整的工作服务器,并试图testing请求响应function。