nock 13.3.0 → 13.3.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 +19 -4
- package/lib/intercept.js +12 -2
- package/lib/socket.js +1 -0
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -9,6 +9,9 @@
|
|
|
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)
|
|
14
|
+
|
|
12
15
|
HTTP server mocking and expectations library for Node.js
|
|
13
16
|
|
|
14
17
|
Nock can be used to test modules that perform HTTP requests in isolation.
|
|
@@ -1002,7 +1005,7 @@ const scope = nock('http://example.com')
|
|
|
1002
1005
|
.reply(200, 'Persisting all the way')
|
|
1003
1006
|
```
|
|
1004
1007
|
|
|
1005
|
-
Note that while a persisted scope will always intercept the requests, it is considered "done" after the first interception.
|
|
1008
|
+
Note that while a persisted scope will always intercept the requests, it is considered "done" after the first interception, and they are pushed to the bottom of the stack after consumption.
|
|
1006
1009
|
|
|
1007
1010
|
If you want to stop persisting an individual persisted mock you can call `persist(false)`:
|
|
1008
1011
|
|
|
@@ -1539,9 +1542,9 @@ import test from 'ava' // You can use any test framework.
|
|
|
1539
1542
|
// can't be intercepted by nock. So, configure axios to use the node adapter.
|
|
1540
1543
|
//
|
|
1541
1544
|
// References:
|
|
1542
|
-
// https://github.com/
|
|
1543
|
-
|
|
1544
|
-
axios.defaults.adapter =
|
|
1545
|
+
// https://github.com/axios/axios/pull/5277
|
|
1546
|
+
|
|
1547
|
+
axios.defaults.adapter = 'http'
|
|
1545
1548
|
|
|
1546
1549
|
test('can fetch test response', async t => {
|
|
1547
1550
|
// Set up the mock request.
|
|
@@ -1559,6 +1562,18 @@ test('can fetch test response', async t => {
|
|
|
1559
1562
|
})
|
|
1560
1563
|
```
|
|
1561
1564
|
|
|
1565
|
+
For Nock + Axios + Jest to work, you'll have to also adapt your jest.config.js, like so:
|
|
1566
|
+
|
|
1567
|
+
```js
|
|
1568
|
+
const config = {
|
|
1569
|
+
moduleNameMapper: {
|
|
1570
|
+
// Force CommonJS build for http adapter to be available.
|
|
1571
|
+
// via https://github.com/axios/axios/issues/5101#issuecomment-1276572468
|
|
1572
|
+
'^axios$': require.resolve('axios'),
|
|
1573
|
+
},
|
|
1574
|
+
}
|
|
1575
|
+
```
|
|
1576
|
+
|
|
1562
1577
|
[axios]: https://github.com/axios/axios
|
|
1563
1578
|
|
|
1564
1579
|
### Memory issues with Jest
|
package/lib/intercept.js
CHANGED
|
@@ -110,7 +110,7 @@ function addInterceptor(key, interceptor, scope, scopeOptions, host) {
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
function remove(interceptor) {
|
|
113
|
-
if (
|
|
113
|
+
if (--interceptor.counter > 0) {
|
|
114
114
|
return
|
|
115
115
|
}
|
|
116
116
|
|
|
@@ -122,6 +122,12 @@ function remove(interceptor) {
|
|
|
122
122
|
// matching instance. I'm also not sure why we couldn't delete _all_
|
|
123
123
|
// matching instances.
|
|
124
124
|
interceptors.some(function (thisInterceptor, i) {
|
|
125
|
+
if (interceptor.__nock_scope.shouldPersist()) {
|
|
126
|
+
return thisInterceptor === interceptor
|
|
127
|
+
? interceptors.push(interceptors.splice(i, 1)[0])
|
|
128
|
+
: false
|
|
129
|
+
}
|
|
130
|
+
|
|
125
131
|
return thisInterceptor === interceptor ? interceptors.splice(i, 1) : false
|
|
126
132
|
})
|
|
127
133
|
}
|
|
@@ -218,7 +224,11 @@ function removeInterceptor(options) {
|
|
|
218
224
|
) {
|
|
219
225
|
for (let i = 0; i < allInterceptors[baseUrl].interceptors.length; i++) {
|
|
220
226
|
const interceptor = allInterceptors[baseUrl].interceptors[i]
|
|
221
|
-
if (
|
|
227
|
+
if (
|
|
228
|
+
options instanceof Interceptor
|
|
229
|
+
? interceptor === options
|
|
230
|
+
: interceptor._key === key
|
|
231
|
+
) {
|
|
222
232
|
allInterceptors[baseUrl].interceptors.splice(i, 1)
|
|
223
233
|
interceptor.scope.remove(key, interceptor)
|
|
224
234
|
break
|
package/lib/socket.js
CHANGED
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"testing",
|
|
8
8
|
"isolation"
|
|
9
9
|
],
|
|
10
|
-
"version": "13.3.
|
|
10
|
+
"version": "13.3.2",
|
|
11
11
|
"author": "Pedro Teixeira <pedro.teixeira@gmail.com>",
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"propagate": "^2.0.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@definitelytyped/dtslint": "^0.0.
|
|
31
|
+
"@definitelytyped/dtslint": "^0.0.163",
|
|
32
32
|
"@sinonjs/fake-timers": "^10.0.0",
|
|
33
33
|
"assert-rejects": "^1.0.0",
|
|
34
34
|
"chai": "^4.1.2",
|
|
@@ -45,13 +45,13 @@
|
|
|
45
45
|
"mocha": "^9.1.3",
|
|
46
46
|
"npm-run-all": "^4.1.5",
|
|
47
47
|
"nyc": "^15.0.0",
|
|
48
|
-
"prettier": "2.
|
|
48
|
+
"prettier": "2.8.8",
|
|
49
49
|
"proxyquire": "^2.1.0",
|
|
50
50
|
"rimraf": "^3.0.0",
|
|
51
|
-
"semantic-release": "^
|
|
51
|
+
"semantic-release": "^21.0.2",
|
|
52
52
|
"sinon": "^15.0.1",
|
|
53
53
|
"sinon-chai": "^3.7.0",
|
|
54
|
-
"typescript": "^
|
|
54
|
+
"typescript": "^5.0.4"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
57
57
|
"format:fix": "prettier --write '**/*.{js,json,md,ts,yml,yaml}'",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"lint": "run-p lint:js lint:ts",
|
|
60
60
|
"lint:js": "eslint --cache --cache-location './.cache/eslint' '**/*.js'",
|
|
61
61
|
"lint:js:fix": "eslint --cache --cache-location './.cache/eslint' --fix '**/*.js'",
|
|
62
|
-
"lint:ts": "dtslint types",
|
|
62
|
+
"lint:ts": "dtslint --expectOnly types",
|
|
63
63
|
"test": "nyc --reporter=lcov --reporter=text mocha tests",
|
|
64
64
|
"test:coverage": "open coverage/lcov-report/index.html"
|
|
65
65
|
},
|