rjz / supertest-session

Persistent sessions for supertest
Other
88 stars 21 forks source link

Promise wrapper method #21

Closed JustinLivi closed 8 years ago

JustinLivi commented 8 years ago

Would you be open to a PR that adds a mongoose-style exec method?

Usage would look like this:

supertest( app )
.get( '/someRoute' )
.expect( 200 )
// wraps supertest.end in a promise
.exec()
.then( function() {
    // success
})
.catch( function( error ) {
    // failure
});
rjz commented 8 years ago

Hey, @JustinLivi! We could do this, but there might be other approaches. @benesch has a promise-based supertest extension in supertest-as-promised that @shaunc previously wrapped—would something like that suit your needs?

If the exec/thunk makes better sense for the use-case, it may be better to follow the pattern of extending this package externally rather than changing the API here. This library has mirrored supertest's continuation-passing API fairly closely (in fact, improving agent support in 'recent' supertest versions has largely mooted this library's raison d'etre), and departing from it may complicate future compatibility changes.

That being said, I'd be very happy to see this extension working in some form!

JustinLivi commented 8 years ago

I wasn't aware of the existence of either of these modules. supertest-session-as-promised looks exactly like what I need, thanks!