expresso
expresso copied to clipboard
assert.response hangs if assertions fail
The assert.response method will hang (or continue to listen) indefinitely if assertions in the callback to response.on('end', ...) fail. The check() method called at the end of the response.on('end', ...) callback is never called if an assertion fails. It may be that the solution is just to move the check() call outside of the response.on('end', ...) callback.
I have to say, I'm new to express, so I'm not certain this is the right thing to do.
unfortunately the only way to be 100% sure that an exit will occur on an error (due to open db connections etc) is to explicitly invoke process.exit(), which might not be a bad idea though sometimes it's nice to see more than one error to see what effect you are really having on the test suite
I think my bug was more basic than that. For example, with the current expresso codebase, if i were to write the following test:
'test that the home page gives us a 1337 status' : function() {
// This, of course, will fail, unless the server is being funny.
assert.response(app,
{ url: '/', headers: {'Host': 'mydomain.com'} },
{ status: 1337 });
},
The test's server will never stop listening because the call to 'check' is made after the assertion fails.
I'm seeing this same behavior. On a new app that I created just to play with Expresso, a single failing assert.response
call hangs the test process after reporting assertion failure as an uncaught exception. Example, assuming a 404
response:
exports["serves static files"] = function() {
assert.response(
{ method: "GET", url: "/favicon.ico" },
{ status: 200 }
);
};
To keep the test process from hanging, I've rewritten the test like this:
exports["serves static files"] = function(beforeExit) {
var res = null;
assert.response(
{ method: "GET", url: "/favicon.ico" },
function(r) { res = r }
);
beforeExit(function() {
assert.equal(200, res.statusCode);
});
};
...but it feels awfully clumsy, especially given the nice response callback that assert.response
already provides. What's the right way to do this?
See also #108.
Ah you got your here perfect, closed my pull in lieu of the solution in pull request #108