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

fix: fix memory leak when using nock with jest #2572

Merged
merged 1 commit into from
Jan 28, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/continuous-integration.yaml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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