visionmedia/supertest — pull request #163 by jussi-kalliokoski (2014-09-19 07:29:29+00:00)
Title: Changed end() to return a Promise when called without arguments.

This is a pretty handy thing to have, especially with Mocha, allowing you to go from this (example from supertest's own tests):

```javascript
it('should support nested requests', function(done){
var app = express();
var test = request(app);

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

test
.get('/')
.end(function(){
test
.get('/')
.end(function(err, res){
(err === null).should.be.true;
res.should.have.status(200);
res.text.should.equal('supertest FTW!');
done();
});
});
});
```

to this:

```javascript
it('should support nested requests', function(){
var app = express();
var test = request(app);

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

return test
.get('/')
.end()
.then(function (res) {
return test
.get('/')
.end();
}).then(function (res) {
res.should.have.status(200);
res.text.should.equal('supertest FTW!');
});
});
```

Or, in a simpler case, the boilerplate reduction is even more obvious:

```javascript
it('should do something', function (done) {
request(app)
.get('/')
.expect(200)
.end(function (err, res) {
if (err) { return done(err); }
done();
});
});
```

vs

```javascript
it('should do something', function(){
return request(app)
.get('/')
.expect(200)
.end();
});
```

Do note that this depends on ES6 Promises so it works only on node 0.11.x and later, but the `es6-promise` polyfill can be used for older versions.