Skip to content

Commit ea12e65

Browse files
committed
Added prefix option for agents
1 parent 199506d commit ea12e65

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Diff for: lib/agent.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function TestAgent(app, options) {
2929
this._ca = options.ca;
3030
this._key = options.key;
3131
this._cert = options.cert;
32+
this._prefix = options.prefix;
3233
}
3334
Agent.call(this);
3435
this.app = app;
@@ -43,7 +44,8 @@ TestAgent.prototype.__proto__ = Agent.prototype;
4344
// override HTTP verb methods
4445
methods.forEach(function(method) {
4546
TestAgent.prototype[method] = function(url, fn) { // eslint-disable-line no-unused-vars
46-
var req = new Test(this.app, method.toUpperCase(), url);
47+
// TODO: support prefix on actual urls
48+
var req = new Test(this.app, method.toUpperCase(), (this._prefix || '') + url);
4749
req.ca(this._ca);
4850
req.cert(this._cert);
4951
req.key(this._key);

Diff for: test/supertest.js

+11
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,17 @@ describe('request.agent(app)', function() {
815815
});
816816
});
817817

818+
describe('request.agent(app, {prefix})', function() {
819+
it('should apply prefix', function(done) {
820+
var app = express();
821+
var agent = request.agent(app, {prefix: '/api'});
822+
823+
agent
824+
.get('/dummy')
825+
.expect(404, 'Cannot GET /api/dummy\n', done);
826+
});
827+
});
828+
818829
describe('.<http verb> works as expected', function() {
819830
it('.delete should work', function (done) {
820831
var app = express();

0 commit comments

Comments
 (0)