Use expresso and socket.io-client to test server, but the testing process does not stop
I wanna use socket.io-client to test my socket.io server. And I tried to run expresso with the following file. The data is printed in console. Then the process hangs there and beforeExit is never executed until I terminate the process with Ctrl-C. I suppose after the callback is done from the server, beforeExit should be called and then the process stops. But it is not like that, Why?
var assert = require('assert');
exports.testAsync = function(beforeExit){
var io = require('socket.io-client');
var socket = io.connect('http://localhost:8000');
socke开发者_JAVA百科t.on('connect', function(err) {
assert.isUndefined(err);
socket.emit('set nickname', 'apple', function(data) {
assert.equal(data, 'ok');
console.log(data);
});
});
beforeExit(function(){
console.log("exit");
socket.disconnect();
});
};
Strange. I'm using Expresso 0.9.2 and exactly the same code you wrote works as expected. But of course, I don't have any server running.
Is this the entire content of your test file?
精彩评论