nock 13.0.6 → 13.0.10
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 +6 -7
- package/lib/common.js +29 -0
- package/lib/intercepted_request_router.js +2 -4
- package/lib/playback_interceptor.js +2 -2
- package/lib/recorder.js +4 -2
- package/lib/socket.js +3 -0
- package/package.json +7 -18
package/README.md
CHANGED
|
@@ -1213,13 +1213,12 @@ nocks.forEach(function (nock) {
|
|
|
1213
1213
|
const recordedBodyResult = /timestamp:([0-9]+)/.exec(aRecordedBody)
|
|
1214
1214
|
if (recordedBodyResult) {
|
|
1215
1215
|
const recordedTimestamp = recordedBodyResult[1]
|
|
1216
|
-
return body.replace(
|
|
1217
|
-
|
|
1218
|
-
key,
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
})
|
|
1216
|
+
return body.replace(
|
|
1217
|
+
/(timestamp):([0-9]+)/g,
|
|
1218
|
+
function (match, key, value) {
|
|
1219
|
+
return key + ':' + recordedTimestamp
|
|
1220
|
+
}
|
|
1221
|
+
)
|
|
1223
1222
|
} else {
|
|
1224
1223
|
return body
|
|
1225
1224
|
}
|
package/lib/common.js
CHANGED
|
@@ -673,6 +673,34 @@ function removeAllTimers() {
|
|
|
673
673
|
clearTimer(clearImmediate, immediates)
|
|
674
674
|
}
|
|
675
675
|
|
|
676
|
+
/**
|
|
677
|
+
* Check if the Client Request has been cancelled.
|
|
678
|
+
*
|
|
679
|
+
* Until Node 14 is the minimum, we need to look at both flags to see if the request has been cancelled.
|
|
680
|
+
* The two flags have the same purpose, but the Node maintainers are migrating from `abort(ed)` to
|
|
681
|
+
* `destroy(ed)` terminology, to be more consistent with `stream.Writable`.
|
|
682
|
+
* In Node 14.x+, Calling `abort()` will set both `aborted` and `destroyed` to true, however,
|
|
683
|
+
* calling `destroy()` will only set `destroyed` to true.
|
|
684
|
+
* Falling back on checking if the socket is destroyed to cover the case of Node <14.x where
|
|
685
|
+
* `destroy()` is called, but `destroyed` is undefined.
|
|
686
|
+
*
|
|
687
|
+
* Node Client Request history:
|
|
688
|
+
* - `request.abort()`: Added in: v0.3.8, Deprecated since: v14.1.0, v13.14.0
|
|
689
|
+
* - `request.aborted`: Added in: v0.11.14, Became a boolean instead of a timestamp: v11.0.0, Not deprecated (yet)
|
|
690
|
+
* - `request.destroy()`: Added in: v0.3.0
|
|
691
|
+
* - `request.destroyed`: Added in: v14.1.0, v13.14.0
|
|
692
|
+
*
|
|
693
|
+
* @param {ClientRequest} req
|
|
694
|
+
* @returns {boolean}
|
|
695
|
+
*/
|
|
696
|
+
function isRequestDestroyed(req) {
|
|
697
|
+
return !!(
|
|
698
|
+
req.destroyed === true ||
|
|
699
|
+
req.aborted ||
|
|
700
|
+
(req.socket && req.socket.destroyed)
|
|
701
|
+
)
|
|
702
|
+
}
|
|
703
|
+
|
|
676
704
|
module.exports = {
|
|
677
705
|
contentEncoding,
|
|
678
706
|
dataEqual,
|
|
@@ -686,6 +714,7 @@ module.exports = {
|
|
|
686
714
|
isContentEncoded,
|
|
687
715
|
isJSONContent,
|
|
688
716
|
isPlainObject,
|
|
717
|
+
isRequestDestroyed,
|
|
689
718
|
isStream,
|
|
690
719
|
isUtf8Representable,
|
|
691
720
|
mapValue,
|
|
@@ -103,8 +103,7 @@ class InterceptedRequestRouter {
|
|
|
103
103
|
connectSocket() {
|
|
104
104
|
const { req, socket } = this
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
if (req.destroyed || req.aborted) {
|
|
106
|
+
if (common.isRequestDestroyed(req)) {
|
|
108
107
|
return
|
|
109
108
|
}
|
|
110
109
|
|
|
@@ -250,8 +249,7 @@ class InterceptedRequestRouter {
|
|
|
250
249
|
return
|
|
251
250
|
}
|
|
252
251
|
|
|
253
|
-
|
|
254
|
-
if (!req.destroyed && !req.aborted && !playbackStarted) {
|
|
252
|
+
if (!common.isRequestDestroyed(req) && !playbackStarted) {
|
|
255
253
|
this.startPlayback()
|
|
256
254
|
}
|
|
257
255
|
}
|
|
@@ -293,7 +293,7 @@ function playbackInterceptor({
|
|
|
293
293
|
const { delayBodyInMs, delayConnectionInMs } = interceptor
|
|
294
294
|
|
|
295
295
|
function respond() {
|
|
296
|
-
if (req
|
|
296
|
+
if (common.isRequestDestroyed(req)) {
|
|
297
297
|
return
|
|
298
298
|
}
|
|
299
299
|
|
|
@@ -318,7 +318,7 @@ function playbackInterceptor({
|
|
|
318
318
|
// correct events are emitted first ('socket', 'finish') and any aborts in the in the queue or
|
|
319
319
|
// called during a 'finish' listener can be called.
|
|
320
320
|
common.setImmediate(() => {
|
|
321
|
-
if (!req
|
|
321
|
+
if (!common.isRequestDestroyed(req)) {
|
|
322
322
|
start()
|
|
323
323
|
}
|
|
324
324
|
})
|
package/lib/recorder.js
CHANGED
|
@@ -110,6 +110,10 @@ function generateRequestAndResponse({
|
|
|
110
110
|
const queryStr = req.path.slice(queryIndex + 1)
|
|
111
111
|
queryObj = querystring.parse(queryStr)
|
|
112
112
|
}
|
|
113
|
+
|
|
114
|
+
// Escape any single quotes in the path as the output uses them
|
|
115
|
+
path = path.replace(/'/g, `\\'`)
|
|
116
|
+
|
|
113
117
|
// Always encode the query parameters when recording.
|
|
114
118
|
const encodedQueryObj = {}
|
|
115
119
|
for (const key in queryObj) {
|
|
@@ -305,8 +309,6 @@ function record(recOptions) {
|
|
|
305
309
|
|
|
306
310
|
if (callback) {
|
|
307
311
|
callback(res, options, callback)
|
|
308
|
-
} else {
|
|
309
|
-
res.resume()
|
|
310
312
|
}
|
|
311
313
|
|
|
312
314
|
debug('finished setting up intercepting')
|
package/lib/socket.js
CHANGED
|
@@ -7,9 +7,12 @@ module.exports = class Socket extends EventEmitter {
|
|
|
7
7
|
constructor(options) {
|
|
8
8
|
super()
|
|
9
9
|
|
|
10
|
+
// Pretend this is a TLSSocket
|
|
10
11
|
if (options.proto === 'https') {
|
|
11
12
|
// https://github.com/nock/nock/issues/158
|
|
12
13
|
this.authorized = true
|
|
14
|
+
// https://github.com/nock/nock/issues/2147
|
|
15
|
+
this.encrypted = true
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
this.bufferSize = 0
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"testing",
|
|
8
8
|
"isolation"
|
|
9
9
|
],
|
|
10
|
-
"version": "13.0.
|
|
10
|
+
"version": "13.0.10",
|
|
11
11
|
"author": "Pedro Teixeira <pedro.teixeira@gmail.com>",
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
@@ -40,13 +40,13 @@
|
|
|
40
40
|
"eslint-plugin-mocha": "^8.0.0",
|
|
41
41
|
"eslint-plugin-node": "^11.0.0",
|
|
42
42
|
"eslint-plugin-promise": "^4.1.1",
|
|
43
|
-
"eslint-plugin-standard": "^
|
|
44
|
-
"form-data": "^
|
|
43
|
+
"eslint-plugin-standard": "^5.0.0",
|
|
44
|
+
"form-data": "^4.0.0",
|
|
45
45
|
"got": "^11.3.0",
|
|
46
46
|
"mocha": "^8.0.1",
|
|
47
47
|
"npm-run-all": "^4.1.5",
|
|
48
48
|
"nyc": "^15.0.0",
|
|
49
|
-
"prettier": "2.
|
|
49
|
+
"prettier": "2.2.1",
|
|
50
50
|
"proxyquire": "^2.1.0",
|
|
51
51
|
"request": "^2.83.0",
|
|
52
52
|
"rimraf": "^3.0.0",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"sinon": "^9.0.0",
|
|
55
55
|
"sinon-chai": "^3.3.0",
|
|
56
56
|
"superagent": "^6.1.0",
|
|
57
|
-
"
|
|
57
|
+
"typescript": "^4.2.2"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"format:fix": "prettier --write '**/*.{js,json,md,ts,yml,yaml}'",
|
|
@@ -63,19 +63,8 @@
|
|
|
63
63
|
"lint:js": "eslint --cache --cache-location './.cache/eslint' '**/*.js'",
|
|
64
64
|
"lint:js:fix": "eslint --cache --cache-location './.cache/eslint' --fix '**/*.js'",
|
|
65
65
|
"lint:ts": "dtslint types",
|
|
66
|
-
"test": "
|
|
67
|
-
"test:coverage": "
|
|
68
|
-
"test:mocha": "nyc mocha $(grep -lr '^\\s*it(' tests)",
|
|
69
|
-
"test:tap": "tap --100 --coverage --coverage-report=text ./tests/test_*.js"
|
|
70
|
-
},
|
|
71
|
-
"nyc": {
|
|
72
|
-
"reporter": [
|
|
73
|
-
"lcov",
|
|
74
|
-
"text-summary"
|
|
75
|
-
],
|
|
76
|
-
"exclude": [
|
|
77
|
-
"tests/"
|
|
78
|
-
]
|
|
66
|
+
"test": "nyc mocha tests",
|
|
67
|
+
"test:coverage": "open coverage/lcov-report/index.html"
|
|
79
68
|
},
|
|
80
69
|
"license": "MIT",
|
|
81
70
|
"files": [
|