nock 13.2.6 → 13.2.9
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 +13 -0
- package/lib/intercepted_request_router.js +7 -1
- package/package.json +3 -3
- package/types/index.d.ts +2 -2
package/README.md
CHANGED
|
@@ -846,11 +846,24 @@ If you need to match requests only if certain request headers match, you can.
|
|
|
846
846
|
|
|
847
847
|
```js
|
|
848
848
|
const scope = nock('http://api.myservice.com')
|
|
849
|
+
// Interceptors created after here will only match when the header `accept` equals `application/json`.
|
|
849
850
|
.matchHeader('accept', 'application/json')
|
|
850
851
|
.get('/')
|
|
851
852
|
.reply(200, {
|
|
852
853
|
data: 'hello world',
|
|
853
854
|
})
|
|
855
|
+
.get('/')
|
|
856
|
+
// Only this interceptor will match the header value `x-my-action` with `MyFirstAction`
|
|
857
|
+
.matchHeader('x-my-action', 'MyFirstAction')
|
|
858
|
+
.reply(200, {
|
|
859
|
+
data: 'FirstActionResponse',
|
|
860
|
+
})
|
|
861
|
+
.get('/')
|
|
862
|
+
// Only this interceptor will match the header value `x-my-action` with `MySecondAction`
|
|
863
|
+
.matchHeader('x-my-action', 'MySecondAction')
|
|
864
|
+
.reply(200, {
|
|
865
|
+
data: 'SecondActionResponse',
|
|
866
|
+
})
|
|
854
867
|
```
|
|
855
868
|
|
|
856
869
|
You can also use a regexp for the header body.
|
|
@@ -143,8 +143,11 @@ class InterceptedRequestRouter {
|
|
|
143
143
|
|
|
144
144
|
// from docs: When write function is called with empty string or buffer, it does nothing and waits for more input.
|
|
145
145
|
// However, actually implementation checks the state of finished and aborted before checking if the first arg is empty.
|
|
146
|
-
handleWrite(
|
|
146
|
+
handleWrite(...args) {
|
|
147
147
|
debug('request write')
|
|
148
|
+
|
|
149
|
+
let [buffer, encoding] = args
|
|
150
|
+
|
|
148
151
|
const { req } = this
|
|
149
152
|
|
|
150
153
|
if (req.finished) {
|
|
@@ -171,6 +174,9 @@ class InterceptedRequestRouter {
|
|
|
171
174
|
}
|
|
172
175
|
this.requestBodyBuffers.push(buffer)
|
|
173
176
|
|
|
177
|
+
// writable.write encoding param is optional
|
|
178
|
+
// so if callback is present it's the last argument
|
|
179
|
+
const callback = args.length > 1 ? args[args.length - 1] : undefined
|
|
174
180
|
// can't use instanceof Function because some test runners
|
|
175
181
|
// run tests in vm.runInNewContext where Function is not same
|
|
176
182
|
// as that in the current context
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"testing",
|
|
8
8
|
"isolation"
|
|
9
9
|
],
|
|
10
|
-
"version": "13.2.
|
|
10
|
+
"version": "13.2.9",
|
|
11
11
|
"author": "Pedro Teixeira <pedro.teixeira@gmail.com>",
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
@@ -45,11 +45,11 @@
|
|
|
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.7.1",
|
|
49
49
|
"proxyquire": "^2.1.0",
|
|
50
50
|
"rimraf": "^3.0.0",
|
|
51
51
|
"semantic-release": "^19.0.2",
|
|
52
|
-
"sinon": "^
|
|
52
|
+
"sinon": "^14.0.0",
|
|
53
53
|
"sinon-chai": "^3.7.0",
|
|
54
54
|
"typescript": "^4.2.2"
|
|
55
55
|
},
|
package/types/index.d.ts
CHANGED