Skip to content

Commit

Permalink
fix(adapter-node-http): Remove module monkey patching on disconnect (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
woodenconsulting authored Nov 18, 2020
1 parent 2ed0aff commit 0cec43a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/@pollyjs/adapter-node-http/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default class HttpAdapter extends Adapter {
}

onDisconnect() {
this.unpatchOverriddenMethods();
nock.cleanAll();
nock.restore();
this.NativeClientRequest = null;
Expand Down Expand Up @@ -120,6 +121,11 @@ export default class HttpAdapter extends Adapter {
const module = modules[moduleName];
const { request, get, globalAgent } = module;

this[moduleName] = {
get,
request
};

function parseArgs() {
const args = normalizeClientRequestArgs(...arguments);

Expand Down Expand Up @@ -152,6 +158,18 @@ export default class HttpAdapter extends Adapter {
});
}

unpatchOverriddenMethods() {
const modules = { http, https };

Object.keys(modules).forEach(moduleName => {
const module = modules[moduleName];

module.request = this[moduleName].request;
module.get = this[moduleName].get;
this[moduleName] = undefined;
});
}

onRequest(pollyRequest) {
const { req } = pollyRequest.requestArguments;

Expand Down

0 comments on commit 0cec43a

Please sign in to comment.