nock 13.4.0 → 13.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -66,6 +66,7 @@ For instance, if a module performs HTTP requests to a CouchDB server or makes HT
66
66
  - [.pendingMocks()](#pendingmocks)
67
67
  - [.activeMocks()](#activemocks)
68
68
  - [.isActive()](#isactive)
69
+ - [.clone()](#clone)
69
70
  - [Restoring](#restoring)
70
71
  - [Activating](#activating)
71
72
  - [Turning Nock Off (experimental!)](#turning-nock-off-experimental)
@@ -89,6 +90,8 @@ For instance, if a module performs HTTP requests to a CouchDB server or makes HT
89
90
  - [Options](#options-1)
90
91
  - [Example](#example)
91
92
  - [Modes](#modes)
93
+ - [Verifying recorded fixtures](#verifying-recorded-fixtures)
94
+ - [Example](#example-1)
92
95
  - [Common issues](#common-issues)
93
96
  - [Axios](#axios)
94
97
  - [Memory issues with Jest](#memory-issues-with-jest)
@@ -1066,6 +1069,17 @@ if (!nock.isActive()) {
1066
1069
  }
1067
1070
  ```
1068
1071
 
1072
+ ### .clone()
1073
+
1074
+ You can clone a scope by calling `.clone()` on it:
1075
+
1076
+ ```js
1077
+ const scope = nock('http://example.test')
1078
+
1079
+ const getScope = scope.get('/').reply(200)
1080
+ const postScope = scope.clone().post('/').reply(200)
1081
+ ```
1082
+
1069
1083
  ## Restoring
1070
1084
 
1071
1085
  You can restore the HTTP interceptor to the normal unmocked behaviour by calling:
@@ -1682,6 +1696,9 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/all-contri
1682
1696
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/Beretta1979"><img src="https://avatars.githubusercontent.com/u/10073962?v=4?s=100" width="100px;" alt="Sébastien Van Bruaene"/><br /><sub><b>Sébastien Van Bruaene</b></sub></a><br /><a href="https://github.com/nock/nock/commits?author=Beretta1979" title="Code">💻</a> <a href="https://github.com/nock/nock/commits?author=Beretta1979" title="Tests">⚠️</a></td>
1683
1697
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/Uzlopak"><img src="https://avatars.githubusercontent.com/u/5059100?v=4?s=100" width="100px;" alt="Aras Abbasi"/><br /><sub><b>Aras Abbasi</b></sub></a><br /><a href="https://github.com/nock/nock/commits?author=Uzlopak" title="Code">💻</a> <a href="https://github.com/nock/nock/commits?author=Uzlopak" title="Tests">⚠️</a> <a href="#maintenance-Uzlopak" title="Maintenance">🚧</a></td>
1684
1698
  </tr>
1699
+ <tr>
1700
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/rsaryev"><img src="https://avatars.githubusercontent.com/u/70219513?v=4?s=100" width="100px;" alt="Saryev Rustam"/><br /><sub><b>Saryev Rustam</b></sub></a><br /><a href="https://github.com/nock/nock/commits?author=rsaryev" title="Code">💻</a> <a href="https://github.com/nock/nock/commits?author=rsaryev" title="Tests">⚠️</a></td>
1701
+ </tr>
1685
1702
  </tbody>
1686
1703
  </table>
1687
1704
 
package/lib/common.js CHANGED
@@ -70,10 +70,7 @@ function overrideRequests(newRequest) {
70
70
  debug('- overriding request for', proto)
71
71
 
72
72
  const moduleName = proto // 1 to 1 match of protocol and module is fortunate :)
73
- const module = {
74
- http: require('http'),
75
- https: require('https'),
76
- }[moduleName]
73
+ const module = require(proto)
77
74
  const overriddenRequest = module.request
78
75
  const overriddenGet = module.get
79
76
 
package/lib/intercept.js CHANGED
@@ -370,8 +370,6 @@ function activate() {
370
370
  throw new Error('Nock already active')
371
371
  }
372
372
 
373
- overrideClientRequest()
374
-
375
373
  // ----- Overriding http.request and https.request:
376
374
 
377
375
  common.overrideRequests(function (proto, overriddenRequest, args) {
@@ -435,6 +433,8 @@ function activate() {
435
433
  }
436
434
  }
437
435
  })
436
+
437
+ overrideClientRequest()
438
438
  }
439
439
 
440
440
  module.exports = {
package/lib/scope.js CHANGED
@@ -286,6 +286,10 @@ class Scope extends EventEmitter {
286
286
  this.date = d || new Date()
287
287
  return this
288
288
  }
289
+
290
+ clone() {
291
+ return new Scope(this.basePath, this.scopeOptions)
292
+ }
289
293
  }
290
294
 
291
295
  function loadDefs(path) {
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "testing",
8
8
  "isolation"
9
9
  ],
10
- "version": "13.4.0",
10
+ "version": "13.5.1",
11
11
  "author": "Pedro Teixeira <pedro.teixeira@gmail.com>",
12
12
  "repository": {
13
13
  "type": "git",
@@ -41,10 +41,11 @@
41
41
  "eslint-plugin-promise": "^6.0.0",
42
42
  "form-data": "^4.0.0",
43
43
  "got": "^11.3.0",
44
+ "jest": "^29.7.0",
44
45
  "mocha": "^9.1.3",
45
46
  "npm-run-all": "^4.1.5",
46
47
  "nyc": "^15.0.0",
47
- "prettier": "3.0.3",
48
+ "prettier": "3.1.0",
48
49
  "proxyquire": "^2.1.0",
49
50
  "rimraf": "^3.0.0",
50
51
  "semantic-release": "^22.0.5",
@@ -60,7 +61,8 @@
60
61
  "lint:js:fix": "eslint --cache --cache-location './.cache/eslint' --fix '**/*.js'",
61
62
  "lint:ts": "dtslint --expectOnly types",
62
63
  "test": "nyc --reporter=lcov --reporter=text mocha --recursive tests",
63
- "test:coverage": "open coverage/lcov-report/index.html"
64
+ "test:coverage": "open coverage/lcov-report/index.html",
65
+ "test:jest": "jest tests_jest --detectLeaks"
64
66
  },
65
67
  "license": "MIT",
66
68
  "files": [