Skip to content

Commit 85c9feb

Browse files
bmancini42Florent Dubost
authored and
Florent Dubost
committed
Adapt to change in superagent lib (#68)
1 parent 8fcb428 commit 85c9feb

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"url": "https://github.com/M6Web/superagent-mock"
1616
},
1717
"peerDependencies": {
18-
"superagent": "^3.5.2"
18+
"superagent": "^3.6.0"
1919
},
2020
"devDependencies": {
2121
"babel-cli": "^6.24.1",
@@ -25,7 +25,7 @@
2525
"eslint": "^3.19.0",
2626
"jest": "20.0.3",
2727
"rimraf": "^2.6.1",
28-
"superagent": "^3.5.2"
28+
"superagent": "^3.6.0"
2929
},
3030
"scripts": {
3131
"clean": "rimraf lib es",

src/superagent-mock.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,28 @@ module.exports = function (superagent, config, logger) {
8686
const isNodeServer = this.hasOwnProperty('cookies');
8787
let response = {};
8888

89-
if (isNodeServer) { // node server
90-
const originalPath = this.path;
91-
this.path = this.url;
92-
this._appendQueryString(this); // use superagent implementation of adding the query
93-
path = this.path; // save the url together with the query
94-
this.path = originalPath; // reverse the addition of query to path by _appendQueryString
95-
} else { // client
89+
if (this._finalizeQueryString) {
90+
// superagent 3.6+
91+
9692
const originalUrl = this.url;
97-
this._appendQueryString(this); // use superagent implementation of adding the query
98-
path = this.url; // save the url together with the query
99-
this.url = originalUrl; // reverse the addition of query to url by _appendQueryString
93+
isNodeServer ? this.request() : this._finalizeQueryString(this);
94+
path = this.url;
95+
this.url = originalUrl;
96+
} else {
97+
// superagent < 3.6
98+
99+
if (isNodeServer) { // node server
100+
const originalPath = this.path;
101+
this.path = this.url;
102+
this._appendQueryString(this); // use superagent implementation of adding the query
103+
path = this.path; // save the url together with the query
104+
this.path = originalPath; // reverse the addition of query to path by _appendQueryString
105+
} else { // client
106+
const originalUrl = this.url;
107+
this._appendQueryString(this); // use superagent implementation of adding the query
108+
path = this.url; // save the url together with the query
109+
this.url = originalUrl; // reverse the addition of query to url by _appendQueryString
110+
}
100111
}
101112

102113
// Attempt to match path against the patterns in fixtures

0 commit comments

Comments
 (0)