From 12aa5b68c2a86944ec91774f3e8d4ce4b343ecf0 Mon Sep 17 00:00:00 2001 From: Michael Solomon Date: Mon, 5 Feb 2024 19:49:13 +0200 Subject: [PATCH] fix: add fetch to the restore function (#2582) --- lib/intercept.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/intercept.js b/lib/intercept.js index 4896f6f5c..9811f0780 100644 --- a/lib/intercept.js +++ b/lib/intercept.js @@ -238,6 +238,8 @@ function removeInterceptor(options) { // Variable where we keep the ClientRequest we have overridden // (which might or might not be node's original http.ClientRequest) let originalClientRequest +// Variable where we keep the fetch we have overridden +let originalFetch function ErroringClientRequest(error) { http.OutgoingMessage.call(this) @@ -339,6 +341,9 @@ function restoreOverriddenClientRequest() { http.ClientRequest = originalClientRequest originalClientRequest = undefined + global.fetch = originalFetch + originalFetch = undefined + debug('- ClientRequest restored') } } @@ -437,7 +442,7 @@ function activate() { } }) - const originalFetch = global.fetch + originalFetch = global.fetch global.fetch = async (input, init = undefined) => { const request = new Request(input, init) const options = common.convertFetchRequestToClientRequest(request)