Skip to content

Commit

Permalink
fix: add fetch to the restore function (#2582)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikicho committed Feb 5, 2024
1 parent 8b8c0c2 commit 12aa5b6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/intercept.js
Expand Up @@ -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)
Expand Down Expand Up @@ -339,6 +341,9 @@ function restoreOverriddenClientRequest() {
http.ClientRequest = originalClientRequest
originalClientRequest = undefined

global.fetch = originalFetch
originalFetch = undefined

debug('- ClientRequest restored')
}
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 12aa5b6

Please sign in to comment.