nock 13.0.0 → 13.0.4
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/CHANGELOG.md +1 -1
- package/README.md +1 -1
- package/lib/common.js +20 -10
- package/lib/intercepted_request_router.js +3 -1
- package/lib/playback_interceptor.js +7 -2
- package/package.json +23 -7
package/CHANGELOG.md
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
Nock’s changelog can be found directly in the [GitHub release notes](https://github.com/nock/nock/releases).
|
|
4
4
|
These are automatically created by [semantic-release](https://github.com/semantic-release/semantic-release) based on their [commit message conventions](https://semantic-release.gitbook.io/semantic-release#commit-message-format).
|
|
5
5
|
|
|
6
|
-
Migration guides are available for major versions in the [migration guides directory](https://github.com/nock/nock/tree/
|
|
6
|
+
Migration guides are available for major versions in the [migration guides directory](https://github.com/nock/nock/tree/main/migration_guides).
|
package/README.md
CHANGED
|
@@ -574,7 +574,7 @@ const scope = nock('http://www.headdy.com')
|
|
|
574
574
|
|
|
575
575
|
#### Including Content-Length Header Automatically
|
|
576
576
|
|
|
577
|
-
When using `
|
|
577
|
+
When using `interceptor.reply()` to set a response body manually, you can have the
|
|
578
578
|
`Content-Length` header calculated automatically.
|
|
579
579
|
|
|
580
580
|
```js
|
package/lib/common.js
CHANGED
|
@@ -180,7 +180,7 @@ function isContentEncoded(headers) {
|
|
|
180
180
|
|
|
181
181
|
function contentEncoding(headers, encoder) {
|
|
182
182
|
const contentEncoding = headers['content-encoding']
|
|
183
|
-
return contentEncoding === encoder
|
|
183
|
+
return contentEncoding !== undefined && contentEncoding.toString() === encoder
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
function isJSONContent(headers) {
|
|
@@ -548,8 +548,15 @@ function urlToOptions(url) {
|
|
|
548
548
|
* - The expected data can use regexp to compare values
|
|
549
549
|
* - JSON path notation and nested objects are considered equal
|
|
550
550
|
*/
|
|
551
|
-
const dataEqual = (expected, actual) =>
|
|
552
|
-
|
|
551
|
+
const dataEqual = (expected, actual) => {
|
|
552
|
+
if (isPlainObject(expected)) {
|
|
553
|
+
expected = expand(expected)
|
|
554
|
+
}
|
|
555
|
+
if (isPlainObject(actual)) {
|
|
556
|
+
actual = expand(actual)
|
|
557
|
+
}
|
|
558
|
+
return deepEqual(expected, actual)
|
|
559
|
+
}
|
|
553
560
|
|
|
554
561
|
/**
|
|
555
562
|
* Converts flat objects whose keys use JSON path notation to nested objects.
|
|
@@ -573,17 +580,20 @@ function deepEqual(expected, actual) {
|
|
|
573
580
|
return expected.test(actual)
|
|
574
581
|
}
|
|
575
582
|
|
|
576
|
-
if (Array.isArray(expected)
|
|
577
|
-
if (
|
|
583
|
+
if (Array.isArray(expected) && Array.isArray(actual)) {
|
|
584
|
+
if (expected.length !== actual.length) {
|
|
578
585
|
return false
|
|
579
586
|
}
|
|
580
587
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
588
|
+
return expected.every((expVal, idx) => deepEqual(expVal, actual[idx]))
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
if (isPlainObject(expected) && isPlainObject(actual)) {
|
|
592
|
+
const allKeys = Array.from(
|
|
593
|
+
new Set(Object.keys(expected).concat(Object.keys(actual)))
|
|
594
|
+
)
|
|
585
595
|
|
|
586
|
-
return
|
|
596
|
+
return allKeys.every(key => deepEqual(expected[key], actual[key]))
|
|
587
597
|
}
|
|
588
598
|
|
|
589
599
|
return expected === actual
|
|
@@ -146,7 +146,7 @@ class InterceptedRequestRouter {
|
|
|
146
146
|
|
|
147
147
|
// It seems odd to return `true` here, not sure why you'd want to have
|
|
148
148
|
// the stream potentially written to more, but it's what Node does.
|
|
149
|
-
// https://github.com/nodejs/node/blob/
|
|
149
|
+
// https://github.com/nodejs/node/blob/a9270dcbeba4316b1e179b77ecb6c46af5aa8c20/lib/_http_outgoing.js#L662-L665
|
|
150
150
|
return true
|
|
151
151
|
}
|
|
152
152
|
|
|
@@ -295,6 +295,8 @@ class InterceptedRequestRouter {
|
|
|
295
295
|
'interceptor identified, starting mocking'
|
|
296
296
|
)
|
|
297
297
|
|
|
298
|
+
matchedInterceptor.markConsumed()
|
|
299
|
+
|
|
298
300
|
// wait to emit the finish event until we know for sure an Interceptor is going to playback.
|
|
299
301
|
// otherwise an unmocked request might emit finish twice.
|
|
300
302
|
req.emit('finish')
|
|
@@ -124,8 +124,6 @@ function playbackInterceptor({
|
|
|
124
124
|
const { logger } = interceptor.scope
|
|
125
125
|
|
|
126
126
|
function start() {
|
|
127
|
-
interceptor.markConsumed()
|
|
128
|
-
interceptor.req = req
|
|
129
127
|
req.headers = req.getHeaders()
|
|
130
128
|
|
|
131
129
|
interceptor.scope.emit('request', req, interceptor, requestBodyString)
|
|
@@ -151,6 +149,13 @@ function playbackInterceptor({
|
|
|
151
149
|
response.rawHeaders = [...interceptor.rawHeaders]
|
|
152
150
|
logger('response.rawHeaders:', response.rawHeaders)
|
|
153
151
|
|
|
152
|
+
// TODO: MAJOR: Don't tack the request onto the interceptor.
|
|
153
|
+
// The only reason we do this is so that it's available inside reply functions.
|
|
154
|
+
// It would be better to pass the request as an argument to the functions instead.
|
|
155
|
+
// Not adding the req as a third arg now because it should first be decided if (path, body, req)
|
|
156
|
+
// is the signature we want to go with going forward.
|
|
157
|
+
interceptor.req = req
|
|
158
|
+
|
|
154
159
|
if (interceptor.replyFunction) {
|
|
155
160
|
const parsedRequestBody = parseJSONRequestBody(req, requestBodyString)
|
|
156
161
|
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"testing",
|
|
8
8
|
"isolation"
|
|
9
9
|
],
|
|
10
|
-
"version": "13.0.
|
|
10
|
+
"version": "13.0.4",
|
|
11
11
|
"author": "Pedro Teixeira <pedro.teixeira@gmail.com>",
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
@@ -33,16 +33,17 @@
|
|
|
33
33
|
"chai": "^4.1.2",
|
|
34
34
|
"dirty-chai": "^2.0.1",
|
|
35
35
|
"dtslint": "^3.0.0",
|
|
36
|
-
"eslint": "^
|
|
36
|
+
"eslint": "^7.3.1",
|
|
37
37
|
"eslint-config-prettier": "^6.0.0",
|
|
38
38
|
"eslint-config-standard": "^14.0.0",
|
|
39
39
|
"eslint-plugin-import": "^2.16.0",
|
|
40
|
-
"eslint-plugin-mocha": "^
|
|
40
|
+
"eslint-plugin-mocha": "^7.0.1",
|
|
41
41
|
"eslint-plugin-node": "^11.0.0",
|
|
42
42
|
"eslint-plugin-promise": "^4.1.1",
|
|
43
43
|
"eslint-plugin-standard": "^4.0.0",
|
|
44
|
-
"
|
|
45
|
-
"
|
|
44
|
+
"form-data": "^3.0.0",
|
|
45
|
+
"got": "^11.3.0",
|
|
46
|
+
"mocha": "^8.0.1",
|
|
46
47
|
"npm-run-all": "^4.1.5",
|
|
47
48
|
"nyc": "^15.0.0",
|
|
48
49
|
"prettier": "2.0.5",
|
|
@@ -62,7 +63,6 @@
|
|
|
62
63
|
"lint:js": "eslint --cache --cache-location './.cache/eslint' '**/*.js'",
|
|
63
64
|
"lint:js:fix": "eslint --cache --cache-location './.cache/eslint' --fix '**/*.js'",
|
|
64
65
|
"lint:ts": "dtslint types",
|
|
65
|
-
"semantic-release": "semantic-release",
|
|
66
66
|
"test": "run-s test:mocha test:tap",
|
|
67
67
|
"test:coverage": "tap --coverage-report=html && open coverage/lcov-report/index.html",
|
|
68
68
|
"test:mocha": "nyc mocha $(grep -lr '^\\s*it(' tests)",
|
|
@@ -82,5 +82,21 @@
|
|
|
82
82
|
"index.js",
|
|
83
83
|
"lib",
|
|
84
84
|
"types/index.d.ts"
|
|
85
|
-
]
|
|
85
|
+
],
|
|
86
|
+
"release": {
|
|
87
|
+
"branches": [
|
|
88
|
+
"+([0-9])?(.{+([0-9]),x}).x",
|
|
89
|
+
"main",
|
|
90
|
+
"next",
|
|
91
|
+
"next-major",
|
|
92
|
+
{
|
|
93
|
+
"name": "beta",
|
|
94
|
+
"prerelease": true
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"name": "alpha",
|
|
98
|
+
"prerelease": true
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
}
|
|
86
102
|
}
|