Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt to change in superagent lib #68

Merged
merged 7 commits into from
Sep 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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