Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix end() not called when app is started manually #651

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/test.js
Expand Up @@ -58,7 +58,7 @@ Test.prototype.serverAddress = function(app, path, host) {
var port;
var protocol;

if (!addr) this._server = app.listen(0);
this._server = addr ? app : app.listen(0);
port = app.address().port;
protocol = app instanceof https.Server ? 'https' : 'http';
return protocol + '://' + (host || '127.0.0.1') + ':' + port + path;
Expand Down
18 changes: 18 additions & 0 deletions test/supertest.js
Expand Up @@ -344,6 +344,24 @@ describe('request(app)', function () {
});
});
});

it('should close server if the app was manually started', function (done) {
const app = express();
let test;

app.get('/', function (req, res) {
res.send('supertest FTW!');
});

test = request(app.listen())
.get('/')
.end(function () {
});

test._server.on('close', function () {
done();
});
});
});

describe('.expect(status[, fn])', function () {
Expand Down