Skip to content

Commit

Permalink
fix: match basePath as regex and path as function (#1147)
Browse files Browse the repository at this point in the history
  • Loading branch information
deeptiagrawa authored and gr2m committed Jun 13, 2018
1 parent 1a03056 commit 933880a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/interceptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ Interceptor.prototype.match = function match(options, body, hostNameOnly) {

if (typeof this.uri === 'function') {
matches = matchQueries &&
method.toUpperCase() + ' ' + proto + '://' + options.host === this.baseUri &&
common.matchStringOrRegexp(matchKey, this.basePath) &&
this.uri.call(this, path);
} else {
matches = method === this.method &&
Expand Down
15 changes: 15 additions & 0 deletions tests/test_intercept.js
Original file line number Diff line number Diff line change
Expand Up @@ -4569,7 +4569,22 @@ test('match domain using regexp', function (t) {
});
});

test('match domain using regexp with path as callback (issue-1137)', function (t) {
nock.cleanAll();
nock(/.*/)
.get(() => true)
.reply(200, 'Match regex');

mikealRequest.get('http://www.regexexample.com/resources', function(err, res, body) {
t.type(err, 'null');
t.equal(res.statusCode, 200);
t.equal(body, 'Match regex');
t.end();
});
});

test('match multiple interceptors with regexp domain (issue-508)', function (t) {
nock.cleanAll();
nock(/chainregex/)
.get('/')
.reply(200, 'Match regex')
Expand Down
6 changes: 3 additions & 3 deletions tests/test_recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ test('records nonstandard ports', function(t) {
// Create test http server and perform the tests while it's up.
var testServer = http.createServer(function(req, res) {
res.end(RESPONSE_BODY);
}).listen(8081, function(err) {
}).listen(8082, function(err) {

t.equal(err, undefined);

Expand Down Expand Up @@ -741,7 +741,7 @@ test('works with clients listening for readable', {skip: process.env.AIRPLANE},
// Create test http server and perform the tests while it's up.
var testServer = http.createServer(function(req, res) {
res.end(RESPONSE_BODY);
}).listen(8081, function(err) {
}).listen(8082, function(err) {

// t.equal(err, undefined);

Expand Down Expand Up @@ -882,7 +882,7 @@ test("respects http.request() consumers", function(t) {
setTimeout(function() {
res.end('bar');
}, 25);
}).listen(8082, function(err) {
}).listen(8083, function(err) {
t.equal(err, undefined);

nock.restore();
Expand Down

0 comments on commit 933880a

Please sign in to comment.