Skip to content

Commit

Permalink
Adapt to change in superagent lib (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmancini42 authored and Florent Dubost committed Sep 14, 2017
1 parent 8fcb428 commit 85c9feb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"url": "https://github.com/M6Web/superagent-mock"
},
"peerDependencies": {
"superagent": "^3.5.2"
"superagent": "^3.6.0"
},
"devDependencies": {
"babel-cli": "^6.24.1",
Expand All @@ -25,7 +25,7 @@
"eslint": "^3.19.0",
"jest": "20.0.3",
"rimraf": "^2.6.1",
"superagent": "^3.5.2"
"superagent": "^3.6.0"
},
"scripts": {
"clean": "rimraf lib es",
Expand Down
31 changes: 21 additions & 10 deletions src/superagent-mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,28 @@ module.exports = function (superagent, config, logger) {
const isNodeServer = this.hasOwnProperty('cookies');
let response = {};

if (isNodeServer) { // node server
const originalPath = this.path;
this.path = this.url;
this._appendQueryString(this); // use superagent implementation of adding the query
path = this.path; // save the url together with the query
this.path = originalPath; // reverse the addition of query to path by _appendQueryString
} else { // client
if (this._finalizeQueryString) {
// superagent 3.6+

const originalUrl = this.url;
this._appendQueryString(this); // use superagent implementation of adding the query
path = this.url; // save the url together with the query
this.url = originalUrl; // reverse the addition of query to url by _appendQueryString
isNodeServer ? this.request() : this._finalizeQueryString(this);
path = this.url;
this.url = originalUrl;
} else {
// superagent < 3.6

if (isNodeServer) { // node server
const originalPath = this.path;
this.path = this.url;
this._appendQueryString(this); // use superagent implementation of adding the query
path = this.path; // save the url together with the query
this.path = originalPath; // reverse the addition of query to path by _appendQueryString
} else { // client
const originalUrl = this.url;
this._appendQueryString(this); // use superagent implementation of adding the query
path = this.url; // save the url together with the query
this.url = originalUrl; // reverse the addition of query to url by _appendQueryString
}
}

// Attempt to match path against the patterns in fixtures
Expand Down

0 comments on commit 85c9feb

Please sign in to comment.