In a perfect world, there would be no ECONREST or ENOTFOUND, or 504, but in the real-world, especially when performing functional/integration tests while another team might be running load tests on a shared test environment, it would be really helpful to not bail at the first sign of trouble.
This enhancement request is for the addition of a '.retry(n)' request option.
i.e.
request(http://mydomain.com)
.post('something_wonderful')
.set('User-Agent', 'tester-testtown-testington')
.send(data)
.retry(3)
.end(function(error, res) {
if (error) throw error;
callback(null, res);
});
Yes, definitely would like to see this.
Related: https://github.com/segmentio/superagent-retry/issues/8
Actually getting it to work is quite easy by using https://github.com/segmentio/superagent-retry.
All that is needed to add .retry(n) support to Supertest is:
npm install superagent-retry --save
And change agent.js from:
/**
* Module dependencies.
*/
var Agent = require('superagent').agent
, methods = require('methods')
, http = require('http')
, Test = require('./test');
to:
/**
* Module dependencies.
*/
var superagent = require('superagent')
, Agent = superagent.agent
, methods = require('methods')
, http = require('http')
, Test = require('./test');
require('superagent-retry')(superagent);
But I don't know if superagent-retry should be included in Supertest by default or to be made available for it as an optional feature.
Actually, it would be nice Supertest allowed Superagent plugins to be set up by the user. I'm not sure if that can currently be done without changes to Supertest code.
I'm actually interested in @kristerkari's last comment - I want to use supertest with superagent-prefix so that my tests don't keep repeating a common portion of the URL path.
Hello,
Any update on this ticket?
Thanks,
Quick note - I was able to get plugins to work by requiring superagent beforehand and applying the plugins before requiring supertest
const superagent = require('superagent');
require('superagent-retry')(superagent);
const supertest = require('supertest');
@zabawaba99 alas this workaround does not work for the module superagent-use. Which is the module I need. Ugh.
Was this issue closed because there are no plans to add retry support for supertest?
Most helpful comment
Actually, it would be nice Supertest allowed Superagent plugins to be set up by the user. I'm not sure if that can currently be done without changes to Supertest code.