TGOlson/dupertest

Inconsistency with node callback convention

Opened this issue · 0 comments

supertest API at the time of this writing works like this:

request(...)
 ...
.end(function idiomaticNodeCallback(error, response) {
});

dupertest, in other hand, works like this:

request(...)
...
.errNext(function thatHandlesError(error) {

})
.end(function thatHandlesTheResponse(response) {
});

The inconsistency make it hard to use both in the same codebase. Let's say that we are using a describe/it based test framework, when we use a request tool we expected that at least the API is consistent. Since dupertest is inconsistent with supertest (and doesn't follow node callbacks convention), then it will be impossible to just shift one with the other. Also, it is pretty common for the error handling .errNext to be forgotten, which will cause the application to get stuck for 5 seconds instead of providing the proper error message:

dupertest example

it('test the request of something', function whenThisTestIsRun(done) {
  request(controller)
    .post(params)
    .end(done); //If an error happens, this is not executed, even though the API is called "end". After n seconds (n for the defined timeout value), the test stops with the "timeout" message
});

supertest example

it('test the request of something', function whenThisTestIsRun(done) {
  request(app)
    .post('/URL')
    .end(done); //If an error happens, this is executed as "done(error)", which makes mocha print the error message successfully (as expected) instead of a "timeout" generic message.
});

Related read: