nock 13.5.0 → 13.5.2

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
@@ -9,8 +9,13 @@
9
9
  [npmjs]: https://www.npmjs.com/package/nock
10
10
  [build]: https://travis-ci.org/nock/nock
11
11
 
12
- > **Warning**
13
- > nock is currently not compatible with Node's experimental native `fetch` implementation. See [#2397](https://github.com/nock/nock/issues/2397)
12
+ > **Notice**
13
+ >
14
+ > We have introduced experimental support for fetch. Please share your feedback with us. You can install it by:
15
+ >
16
+ > ```
17
+ > npm install --save-dev nock@beta
18
+ > ```
14
19
 
15
20
  HTTP server mocking and expectations library for Node.js
16
21
 
@@ -66,6 +71,7 @@ For instance, if a module performs HTTP requests to a CouchDB server or makes HT
66
71
  - [.pendingMocks()](#pendingmocks)
67
72
  - [.activeMocks()](#activemocks)
68
73
  - [.isActive()](#isactive)
74
+ - [.clone()](#clone)
69
75
  - [Restoring](#restoring)
70
76
  - [Activating](#activating)
71
77
  - [Turning Nock Off (experimental!)](#turning-nock-off-experimental)
@@ -89,6 +95,8 @@ For instance, if a module performs HTTP requests to a CouchDB server or makes HT
89
95
  - [Options](#options-1)
90
96
  - [Example](#example)
91
97
  - [Modes](#modes)
98
+ - [Verifying recorded fixtures](#verifying-recorded-fixtures)
99
+ - [Example](#example-1)
92
100
  - [Common issues](#common-issues)
93
101
  - [Axios](#axios)
94
102
  - [Memory issues with Jest](#memory-issues-with-jest)
@@ -1693,6 +1701,10 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/all-contri
1693
1701
  <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>
1694
1702
  <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>
1695
1703
  </tr>
1704
+ <tr>
1705
+ <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>
1706
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/mikicho"><img src="https://avatars.githubusercontent.com/u/11459632?v=4?s=100" width="100px;" alt="Michael Solomon"/><br /><sub><b>Michael Solomon</b></sub></a><br /><a href="#maintenance-mikicho" title="Maintenance">🚧</a> <a href="https://github.com/nock/nock/commits?author=mikicho" title="Code">💻</a> <a href="https://github.com/nock/nock/commits?author=mikicho" title="Documentation">📖</a></td>
1707
+ </tr>
1696
1708
  </tbody>
1697
1709
  </table>
1698
1710
 
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
@@ -350,7 +350,8 @@ function interceptorScopes() {
350
350
  const nestedInterceptors = Object.values(allInterceptors).map(
351
351
  i => i.interceptors,
352
352
  )
353
- return [].concat(...nestedInterceptors).map(i => i.scope)
353
+ const scopes = new Set([].concat(...nestedInterceptors).map(i => i.scope))
354
+ return [...scopes]
354
355
  }
355
356
 
356
357
  function isDone() {
@@ -370,8 +371,6 @@ function activate() {
370
371
  throw new Error('Nock already active')
371
372
  }
372
373
 
373
- overrideClientRequest()
374
-
375
374
  // ----- Overriding http.request and https.request:
376
375
 
377
376
  common.overrideRequests(function (proto, overriddenRequest, args) {
@@ -435,6 +434,8 @@ function activate() {
435
434
  }
436
435
  }
437
436
  })
437
+
438
+ overrideClientRequest()
438
439
  }
439
440
 
440
441
  module.exports = {
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "testing",
8
8
  "isolation"
9
9
  ],
10
- "version": "13.5.0",
10
+ "version": "13.5.2",
11
11
  "author": "Pedro Teixeira <pedro.teixeira@gmail.com>",
12
12
  "repository": {
13
13
  "type": "git",
@@ -41,6 +41,7 @@
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",
@@ -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": [