test: fix "socket hang up" error in app.test
Rework the test to always wait for the client request to finish before calling the test done.
This commit is contained in:
parent
593fd6e042
commit
2eec008e0e
|
@ -1046,8 +1046,18 @@ describe('app', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
function executeMiddlewareHandlers(app, urlPath, callback) {
|
function executeMiddlewareHandlers(app, urlPath, callback) {
|
||||||
|
var handlerError;
|
||||||
var server = http.createServer(function(req, res) {
|
var server = http.createServer(function(req, res) {
|
||||||
app.handle(req, res, callback);
|
app.handle(req, res, function(err) {
|
||||||
|
if (err) {
|
||||||
|
handlerError = err;
|
||||||
|
res.statusCode = err.status || err.statusCode || 500;
|
||||||
|
res.end(err.stack || err);
|
||||||
|
} else {
|
||||||
|
res.statusCode = 204;
|
||||||
|
res.end();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (callback === undefined && typeof urlPath === 'function') {
|
if (callback === undefined && typeof urlPath === 'function') {
|
||||||
|
@ -1058,6 +1068,6 @@ function executeMiddlewareHandlers(app, urlPath, callback) {
|
||||||
request(server)
|
request(server)
|
||||||
.get(urlPath)
|
.get(urlPath)
|
||||||
.end(function(err) {
|
.end(function(err) {
|
||||||
if (err) return callback(err);
|
callback(handlerError || err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue