nock 13.2.2 → 13.2.5
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/lib/common.js +2 -47
- package/lib/intercepted_request_router.js +8 -2
- package/lib/interceptor.js +7 -3
- package/lib/match_body.js +5 -4
- package/lib/playback_interceptor.js +2 -2
- package/package.json +11 -12
package/lib/common.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const debug = require('debug')('nock.common')
|
|
4
|
-
const
|
|
4
|
+
const isPlainObject = require('lodash/isPlainObject')
|
|
5
|
+
const set = require('lodash/set')
|
|
5
6
|
const timers = require('timers')
|
|
6
7
|
const url = require('url')
|
|
7
8
|
const util = require('util')
|
|
@@ -608,51 +609,6 @@ function deepEqual(expected, actual) {
|
|
|
608
609
|
return expected === actual
|
|
609
610
|
}
|
|
610
611
|
|
|
611
|
-
/**
|
|
612
|
-
* Checks if `value` is a plain object, that is, an object created by the
|
|
613
|
-
* `Object` constructor or one with a `[[Prototype]]` of `null`.
|
|
614
|
-
* https://github.com/lodash/lodash/blob/588bf3e20db0ae039a822a14a8fa238c5b298e65/isPlainObject.js
|
|
615
|
-
*
|
|
616
|
-
* @param {*} value The value to check.
|
|
617
|
-
* @return {boolean}
|
|
618
|
-
*/
|
|
619
|
-
function isPlainObject(value) {
|
|
620
|
-
const isObjectLike = typeof value === 'object' && value !== null
|
|
621
|
-
const tag = Object.prototype.toString.call(value)
|
|
622
|
-
if (!isObjectLike || tag !== '[object Object]') {
|
|
623
|
-
return false
|
|
624
|
-
}
|
|
625
|
-
if (Object.getPrototypeOf(value) === null) {
|
|
626
|
-
return true
|
|
627
|
-
}
|
|
628
|
-
let proto = value
|
|
629
|
-
while (Object.getPrototypeOf(proto) !== null) {
|
|
630
|
-
proto = Object.getPrototypeOf(proto)
|
|
631
|
-
}
|
|
632
|
-
return Object.getPrototypeOf(value) === proto
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
/**
|
|
636
|
-
* Creates an object with the same keys as `object` and values generated
|
|
637
|
-
* by running each own enumerable string keyed property of `object` thru
|
|
638
|
-
* `iteratee`. (iteration order is not guaranteed)
|
|
639
|
-
* The iteratee is invoked with three arguments: (value, key, object).
|
|
640
|
-
* https://github.com/lodash/lodash/blob/588bf3e20db0ae039a822a14a8fa238c5b298e65/mapValue.js
|
|
641
|
-
*
|
|
642
|
-
* @param {Object} object The object to iterate over.
|
|
643
|
-
* @param {Function} iteratee The function invoked per iteration.
|
|
644
|
-
* @returns {Object} Returns the new mapped object.
|
|
645
|
-
*/
|
|
646
|
-
function mapValue(object, iteratee) {
|
|
647
|
-
object = Object(object)
|
|
648
|
-
const result = {}
|
|
649
|
-
|
|
650
|
-
Object.keys(object).forEach(key => {
|
|
651
|
-
result[key] = iteratee(object[key], key, object)
|
|
652
|
-
})
|
|
653
|
-
return result
|
|
654
|
-
}
|
|
655
|
-
|
|
656
612
|
const timeouts = []
|
|
657
613
|
const intervals = []
|
|
658
614
|
const immediates = []
|
|
@@ -725,7 +681,6 @@ module.exports = {
|
|
|
725
681
|
isRequestDestroyed,
|
|
726
682
|
isStream,
|
|
727
683
|
isUtf8Representable,
|
|
728
|
-
mapValue,
|
|
729
684
|
matchStringOrRegexp,
|
|
730
685
|
normalizeClientRequestArgs,
|
|
731
686
|
normalizeOrigin,
|
|
@@ -51,8 +51,14 @@ class InterceptedRequestRouter {
|
|
|
51
51
|
|
|
52
52
|
// support setting `timeout` using request `options`
|
|
53
53
|
// https://nodejs.org/docs/latest-v12.x/api/http.html#http_http_request_url_options_callback
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
// any timeout in the request options override any timeout in the agent options.
|
|
55
|
+
// per https://github.com/nodejs/node/pull/21204
|
|
56
|
+
const timeout =
|
|
57
|
+
options.timeout ||
|
|
58
|
+
(options.agent && options.agent.options && options.agent.options.timeout)
|
|
59
|
+
|
|
60
|
+
if (timeout) {
|
|
61
|
+
this.socket.setTimeout(timeout)
|
|
56
62
|
}
|
|
57
63
|
|
|
58
64
|
this.response = new IncomingMessage(this.socket)
|
package/lib/interceptor.js
CHANGED
|
@@ -156,7 +156,7 @@ module.exports = class Interceptor {
|
|
|
156
156
|
)
|
|
157
157
|
|
|
158
158
|
// If the content is not encoded we may need to transform the response body.
|
|
159
|
-
// Otherwise we leave it as it is.
|
|
159
|
+
// Otherwise, we leave it as it is.
|
|
160
160
|
if (
|
|
161
161
|
body &&
|
|
162
162
|
typeof body !== 'string' &&
|
|
@@ -174,10 +174,14 @@ module.exports = class Interceptor {
|
|
|
174
174
|
// https://tools.ietf.org/html/rfc7231#section-3.1.1.5
|
|
175
175
|
this.rawHeaders.push('Content-Type', 'application/json')
|
|
176
176
|
}
|
|
177
|
+
}
|
|
177
178
|
|
|
178
|
-
|
|
179
|
-
|
|
179
|
+
if (this.scope.contentLen) {
|
|
180
|
+
// https://tools.ietf.org/html/rfc7230#section-3.3.2
|
|
181
|
+
if (typeof body === 'string') {
|
|
180
182
|
this.rawHeaders.push('Content-Length', body.length)
|
|
183
|
+
} else if (Buffer.isBuffer(body)) {
|
|
184
|
+
this.rawHeaders.push('Content-Length', body.byteLength)
|
|
181
185
|
}
|
|
182
186
|
}
|
|
183
187
|
|
package/lib/match_body.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const mapValues = require('lodash/mapValues')
|
|
3
4
|
const querystring = require('querystring')
|
|
4
5
|
|
|
5
6
|
const common = require('./common')
|
|
@@ -43,7 +44,7 @@ module.exports = function matchBody(options, spec, body) {
|
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
// strip line endings from both so that we get a match no matter what OS we are running on
|
|
46
|
-
// if Content-Type does not
|
|
47
|
+
// if Content-Type does not contain 'multipart'
|
|
47
48
|
if (!isMultipart && typeof body === 'string') {
|
|
48
49
|
body = body.replace(/\r?\n|\r/g, '')
|
|
49
50
|
}
|
|
@@ -52,8 +53,8 @@ module.exports = function matchBody(options, spec, body) {
|
|
|
52
53
|
spec = spec.replace(/\r?\n|\r/g, '')
|
|
53
54
|
}
|
|
54
55
|
|
|
55
|
-
// Because the nature of URL encoding, all the values in the body
|
|
56
|
-
// dataEqual does strict checking so we
|
|
56
|
+
// Because the nature of URL encoding, all the values in the body must be cast to strings.
|
|
57
|
+
// dataEqual does strict checking, so we have to cast the non-regexp values in the spec too.
|
|
57
58
|
if (isUrlencoded) {
|
|
58
59
|
spec = mapValuesDeep(spec, val => (val instanceof RegExp ? val : `${val}`))
|
|
59
60
|
}
|
|
@@ -70,7 +71,7 @@ function mapValuesDeep(obj, cb) {
|
|
|
70
71
|
return obj.map(v => mapValuesDeep(v, cb))
|
|
71
72
|
}
|
|
72
73
|
if (common.isPlainObject(obj)) {
|
|
73
|
-
return
|
|
74
|
+
return mapValues(obj, v => mapValuesDeep(v, cb))
|
|
74
75
|
}
|
|
75
76
|
return cb(obj)
|
|
76
77
|
}
|
|
@@ -79,7 +79,7 @@ class ReadableBuffers extends stream.Readable {
|
|
|
79
79
|
this.buffers = buffers
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
_read(
|
|
82
|
+
_read(_size) {
|
|
83
83
|
while (this.buffers.length) {
|
|
84
84
|
if (!this.push(this.buffers.shift())) {
|
|
85
85
|
return
|
|
@@ -315,7 +315,7 @@ function playbackInterceptor({
|
|
|
315
315
|
|
|
316
316
|
// Calling `start` immediately could take the request all the way to the connection delay
|
|
317
317
|
// during a single microtask execution. This setImmediate stalls the playback to ensure the
|
|
318
|
-
// correct events are emitted first ('socket', 'finish') and any aborts in the
|
|
318
|
+
// correct events are emitted first ('socket', 'finish') and any aborts in the queue or
|
|
319
319
|
// called during a 'finish' listener can be called.
|
|
320
320
|
common.setImmediate(() => {
|
|
321
321
|
if (!common.isRequestDestroyed(req)) {
|
package/package.json
CHANGED
|
@@ -7,14 +7,14 @@
|
|
|
7
7
|
"testing",
|
|
8
8
|
"isolation"
|
|
9
9
|
],
|
|
10
|
-
"version": "13.2.
|
|
10
|
+
"version": "13.2.5",
|
|
11
11
|
"author": "Pedro Teixeira <pedro.teixeira@gmail.com>",
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
14
|
"url": "https://github.com/nock/nock.git"
|
|
15
15
|
},
|
|
16
16
|
"bugs": {
|
|
17
|
-
"url": "
|
|
17
|
+
"url": "https://github.com/nock/nock/issues"
|
|
18
18
|
},
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">= 10.13"
|
|
@@ -24,33 +24,32 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"debug": "^4.1.0",
|
|
26
26
|
"json-stringify-safe": "^5.0.1",
|
|
27
|
-
"lodash
|
|
27
|
+
"lodash": "^4.17.21",
|
|
28
28
|
"propagate": "^2.0.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@
|
|
31
|
+
"@definitelytyped/dtslint": "^0.0.112",
|
|
32
|
+
"@sinonjs/fake-timers": "^9.0.0",
|
|
32
33
|
"assert-rejects": "^1.0.0",
|
|
33
34
|
"chai": "^4.1.2",
|
|
34
35
|
"dirty-chai": "^2.0.1",
|
|
35
|
-
"
|
|
36
|
-
"eslint": "^7.3.1",
|
|
36
|
+
"eslint": "^8.8.0",
|
|
37
37
|
"eslint-config-prettier": "^8.1.0",
|
|
38
|
-
"eslint-config-standard": "^
|
|
38
|
+
"eslint-config-standard": "^17.0.0-0",
|
|
39
39
|
"eslint-plugin-import": "^2.16.0",
|
|
40
40
|
"eslint-plugin-mocha": "^10.0.3",
|
|
41
41
|
"eslint-plugin-node": "^11.0.0",
|
|
42
42
|
"eslint-plugin-promise": "^6.0.0",
|
|
43
|
-
"eslint-plugin-standard": "^5.0.0",
|
|
44
43
|
"form-data": "^4.0.0",
|
|
45
|
-
"got": "^
|
|
44
|
+
"got": "^12.1.0",
|
|
46
45
|
"mocha": "^9.1.3",
|
|
47
46
|
"npm-run-all": "^4.1.5",
|
|
48
47
|
"nyc": "^15.0.0",
|
|
49
|
-
"prettier": "2.
|
|
48
|
+
"prettier": "2.6.2",
|
|
50
49
|
"proxyquire": "^2.1.0",
|
|
51
50
|
"rimraf": "^3.0.0",
|
|
52
|
-
"semantic-release": "^
|
|
53
|
-
"sinon": "^
|
|
51
|
+
"semantic-release": "^19.0.2",
|
|
52
|
+
"sinon": "^13.0.1",
|
|
54
53
|
"sinon-chai": "^3.7.0",
|
|
55
54
|
"typescript": "^4.2.2"
|
|
56
55
|
},
|