Skip to content

Commit

Permalink
fix: memory leak when using nock with jest (#2572)
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirChuprazov committed Jan 28, 2024
1 parent ccfa96d commit 7468cf1
Show file tree
Hide file tree
Showing 6 changed files with 4,951 additions and 1,361 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/continuous-integration.yaml
Expand Up @@ -80,6 +80,9 @@ jobs:
run: npm ci --ignore-scripts --no-audit --no-progress --prefer-offline
- name: Test
run: npm run test
- name: Test jest
run: npm run test:jest
if: matrix.node-version >= 14
strategy:
fail-fast: false
matrix:
Expand Down
5 changes: 1 addition & 4 deletions lib/common.js
Expand Up @@ -70,10 +70,7 @@ function overrideRequests(newRequest) {
debug('- overriding request for', proto)

const moduleName = proto // 1 to 1 match of protocol and module is fortunate :)
const module = {
http: require('http'),
https: require('https'),
}[moduleName]
const module = require(proto)
const overriddenRequest = module.request
const overriddenGet = module.get

Expand Down
4 changes: 2 additions & 2 deletions lib/intercept.js
Expand Up @@ -370,8 +370,6 @@ function activate() {
throw new Error('Nock already active')
}

overrideClientRequest()

// ----- Overriding http.request and https.request:

common.overrideRequests(function (proto, overriddenRequest, args) {
Expand Down Expand Up @@ -435,6 +433,8 @@ function activate() {
}
}
})

overrideClientRequest()
}

module.exports = {
Expand Down

0 comments on commit 7468cf1

Please sign in to comment.