Skip to content

Commit

Permalink
Merge pull request #217 from martypdx/master
Browse files Browse the repository at this point in the history
Enable closing after "keepOpen()" has been called
  • Loading branch information
JamesMessinger committed Jul 24, 2018
2 parents d9a8d1f + 25600aa commit 1af976d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/request.js
Expand Up @@ -225,16 +225,22 @@ module.exports = function (app) {
return this
}
obj.close = function(callback) {
if (server && server.close && keepOpen === false) {
if (server && server.close) {
server.close(callback);
}
else if(callback) {
callback();
}

return this
}
methods.forEach(function (method) {
obj[method] = function (path) {
return new Test(server, method, path)
.on('end', function() {
obj.close();
if(keepOpen === false) {
obj.close();
}
});
};
});
Expand Down
12 changes: 12 additions & 0 deletions test/request.js
Expand Up @@ -205,8 +205,20 @@ describe('request', function () {
});
});

it('can close server after using keepOpen()', function (done) {
var server = require('http').createServer(function (req, res) {
res.writeHeader(200, { 'content-type' : 'text/plain' });
res.end('hello world');
});
var cachedRequest = request(server).keepOpen();
cachedRequest.close(function (err) {
should.not.exist(server.address());
done();
});
});

});

isBrowser && describe('Browser', function () {
it('cannot request a functioned "app"', function () {
function tryToRequestAFunctionedApp() {
Expand Down

0 comments on commit 1af976d

Please sign in to comment.