nock 13.3.4 β 13.3.6
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 +21 -18
- package/lib/common.js +87 -13
- package/lib/match_body.js +8 -1
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -1228,7 +1228,7 @@ The returned call objects have the following properties:
|
|
|
1228
1228
|
- `body` - the body of the call, if any
|
|
1229
1229
|
- `status` - the HTTP status of the reply (e.g. `200`)
|
|
1230
1230
|
- `response` - the body of the reply which can be a JSON, string, hex string representing binary buffers or an array of such hex strings (when handling `content-encoded` in reply header)
|
|
1231
|
-
- `
|
|
1231
|
+
- `rawHeaders` - the headers of the reply which are formatted as a flat array containing header name and header value pairs (e.g. `['accept', 'application/json', 'set-cookie', 'my-cookie=value']`)
|
|
1232
1232
|
- `reqheader` - the headers of the request
|
|
1233
1233
|
|
|
1234
1234
|
If you save this as a JSON file, you can load them directly through `nock.load(path)`. Then you can post-process them before using them in the tests. For example, to add request body filtering (shown here fixing timestamps to match the ones captured during recording):
|
|
@@ -1624,23 +1624,26 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/all-contri
|
|
|
1624
1624
|
<!-- prettier-ignore-start -->
|
|
1625
1625
|
<!-- markdownlint-disable -->
|
|
1626
1626
|
<table>
|
|
1627
|
-
<
|
|
1628
|
-
<
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
<
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1627
|
+
<tbody>
|
|
1628
|
+
<tr>
|
|
1629
|
+
<td align="center" valign="top" width="14.28%"><a href="http://pgte.me"><img src="https://avatars1.githubusercontent.com/u/47910?v=4?s=100" width="100px;" alt="Pedro Teixeira"/><br /><sub><b>Pedro Teixeira</b></sub></a><br /><a href="https://github.com/nock/nock/commits?author=pgte" title="Code">π»</a> <a href="#maintenance-pgte" title="Maintenance">π§</a></td>
|
|
1630
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/n30n0v"><img src="https://avatars3.githubusercontent.com/u/10771967?v=4?s=100" width="100px;" alt="n30n0v"/><br /><sub><b>n30n0v</b></sub></a><br /><a href="https://github.com/nock/nock/commits?author=n30n0v" title="Code">π»</a></td>
|
|
1631
|
+
<td align="center" valign="top" width="14.28%"><a href="https://burntfen.com"><img src="https://avatars3.githubusercontent.com/u/910753?v=4?s=100" width="100px;" alt="Richard Littauer"/><br /><sub><b>Richard Littauer</b></sub></a><br /><a href="#maintenance-RichardLitt" title="Maintenance">π§</a> <a href="https://github.com/nock/nock/commits?author=RichardLitt" title="Code">π»</a> <a href="#blog-RichardLitt" title="Blogposts">π</a></td>
|
|
1632
|
+
<td align="center" valign="top" width="14.28%"><a href="http://ianwsperber.com"><img src="https://avatars1.githubusercontent.com/u/3731165?v=4?s=100" width="100px;" alt="Ian Walker-Sperber"/><br /><sub><b>Ian Walker-Sperber</b></sub></a><br /><a href="https://github.com/nock/nock/commits?author=ianwsperber" title="Code">π»</a></td>
|
|
1633
|
+
<td align="center" valign="top" width="14.28%"><a href="http://ilovacha.com"><img src="https://avatars2.githubusercontent.com/u/1505203?v=4?s=100" width="100px;" alt="Ivan Erceg"/><br /><sub><b>Ivan Erceg</b></sub></a><br /><a href="https://github.com/nock/nock/commits?author=ierceg" title="Code">π»</a> <a href="#maintenance-ierceg" title="Maintenance">π§</a></td>
|
|
1634
|
+
<td align="center" valign="top" width="14.28%"><a href="https://twitter.com/paulmelnikow"><img src="https://avatars2.githubusercontent.com/u/1487036?v=4?s=100" width="100px;" alt="Paul Melnikow"/><br /><sub><b>Paul Melnikow</b></sub></a><br /><a href="https://github.com/nock/nock/commits?author=paulmelnikow" title="Code">π»</a> <a href="#maintenance-paulmelnikow" title="Maintenance">π§</a></td>
|
|
1635
|
+
<td align="center" valign="top" width="14.28%"><a href="https://twitter.com/gr2m"><img src="https://avatars3.githubusercontent.com/u/39992?v=4?s=100" width="100px;" alt="Gregor Martynus"/><br /><sub><b>Gregor Martynus</b></sub></a><br /><a href="https://github.com/nock/nock/commits?author=gr2m" title="Code">π»</a> <a href="#maintenance-gr2m" title="Maintenance">π§</a> <a href="#business-gr2m" title="Business development">πΌ</a> <a href="#financial-gr2m" title="Financial">π΅</a> <a href="#blog-gr2m" title="Blogposts">π</a></td>
|
|
1636
|
+
</tr>
|
|
1637
|
+
<tr>
|
|
1638
|
+
<td align="center" valign="top" width="14.28%"><a href="https://gitlab.com/hutson"><img src="https://avatars1.githubusercontent.com/u/6701030?v=4?s=100" width="100px;" alt="Hutson Betts"/><br /><sub><b>Hutson Betts</b></sub></a><br /><a href="#financial-hutson" title="Financial">π΅</a></td>
|
|
1639
|
+
<td align="center" valign="top" width="14.28%"><a href="http://lilja.io"><img src="https://avatars2.githubusercontent.com/u/6105119?v=4?s=100" width="100px;" alt="Jonas Lilja"/><br /><sub><b>Jonas Lilja</b></sub></a><br /><a href="#financial-jlilja" title="Financial">π΅</a> <a href="https://github.com/nock/nock/commits?author=jlilja" title="Code">π»</a></td>
|
|
1640
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/benrki"><img src="https://avatars0.githubusercontent.com/u/4446950?v=4?s=100" width="100px;" alt="Benjamin Ki"/><br /><sub><b>Benjamin Ki</b></sub></a><br /><a href="#financial-benrki" title="Financial">π΅</a></td>
|
|
1641
|
+
<td align="center" valign="top" width="14.28%"><a href="http://chadf.ca"><img src="https://avatars2.githubusercontent.com/u/3250463?v=4?s=100" width="100px;" alt="Chad Fawcett"/><br /><sub><b>Chad Fawcett</b></sub></a><br /><a href="#financial-chadfawcett" title="Financial">π΅</a></td>
|
|
1642
|
+
<td align="center" valign="top" width="14.28%"><a href="http://www.laurencemyers.com.au"><img src="https://avatars.githubusercontent.com/u/6336048?v=4?s=100" width="100px;" alt="Laurence Dougal Myers"/><br /><sub><b>Laurence Dougal Myers</b></sub></a><br /><a href="https://github.com/nock/nock/commits?author=laurence-myers" title="Code">π»</a></td>
|
|
1643
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Beretta1979"><img src="https://avatars.githubusercontent.com/u/10073962?v=4?s=100" width="100px;" alt="SΓ©bastien Van Bruaene"/><br /><sub><b>SΓ©bastien Van Bruaene</b></sub></a><br /><a href="https://github.com/nock/nock/commits?author=Beretta1979" title="Code">π»</a> <a href="https://github.com/nock/nock/commits?author=Beretta1979" title="Tests">β οΈ</a></td>
|
|
1644
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Uzlopak"><img src="https://avatars.githubusercontent.com/u/5059100?v=4?s=100" width="100px;" alt="Aras Abbasi"/><br /><sub><b>Aras Abbasi</b></sub></a><br /><a href="https://github.com/nock/nock/commits?author=Uzlopak" title="Code">π»</a> <a href="https://github.com/nock/nock/commits?author=Uzlopak" title="Tests">β οΈ</a> <a href="#maintenance-Uzlopak" title="Maintenance">π§</a></td>
|
|
1645
|
+
</tr>
|
|
1646
|
+
</tbody>
|
|
1644
1647
|
</table>
|
|
1645
1648
|
|
|
1646
1649
|
<!-- markdownlint-restore -->
|
package/lib/common.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const debug = require('debug')('nock.common')
|
|
4
|
-
const isPlainObject = require('lodash/isPlainObject')
|
|
5
|
-
const set = require('lodash/set')
|
|
6
4
|
const timers = require('timers')
|
|
7
5
|
const url = require('url')
|
|
8
6
|
const util = require('util')
|
|
@@ -568,17 +566,6 @@ const dataEqual = (expected, actual) => {
|
|
|
568
566
|
return deepEqual(expected, actual)
|
|
569
567
|
}
|
|
570
568
|
|
|
571
|
-
/**
|
|
572
|
-
* Converts flat objects whose keys use JSON path notation to nested objects.
|
|
573
|
-
*
|
|
574
|
-
* The input object is not mutated.
|
|
575
|
-
*
|
|
576
|
-
* @example
|
|
577
|
-
* { 'foo[bar][0]': 'baz' } -> { foo: { bar: [ 'baz' ] } }
|
|
578
|
-
*/
|
|
579
|
-
const expand = input =>
|
|
580
|
-
Object.entries(input).reduce((acc, [k, v]) => set(acc, k, v), {})
|
|
581
|
-
|
|
582
569
|
/**
|
|
583
570
|
* Performs a recursive strict comparison between two values.
|
|
584
571
|
*
|
|
@@ -665,10 +652,97 @@ function isRequestDestroyed(req) {
|
|
|
665
652
|
)
|
|
666
653
|
}
|
|
667
654
|
|
|
655
|
+
/**
|
|
656
|
+
* Returns true if the given value is a plain object and not an Array.
|
|
657
|
+
* @param {*} value
|
|
658
|
+
* @returns {boolean}
|
|
659
|
+
*/
|
|
660
|
+
function isPlainObject(value) {
|
|
661
|
+
if (typeof value !== 'object' || value === null) return false
|
|
662
|
+
|
|
663
|
+
if (Object.prototype.toString.call(value) !== '[object Object]') return false
|
|
664
|
+
|
|
665
|
+
const proto = Object.getPrototypeOf(value)
|
|
666
|
+
if (proto === null) return true
|
|
667
|
+
|
|
668
|
+
const Ctor =
|
|
669
|
+
Object.prototype.hasOwnProperty.call(proto, 'constructor') &&
|
|
670
|
+
proto.constructor
|
|
671
|
+
return (
|
|
672
|
+
typeof Ctor === 'function' &&
|
|
673
|
+
Ctor instanceof Ctor &&
|
|
674
|
+
Function.prototype.call(Ctor) === Function.prototype.call(value)
|
|
675
|
+
)
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
const prototypePollutionBlockList = ['__proto__', 'prototype', 'constructor']
|
|
679
|
+
const blocklistFilter = function (part) {
|
|
680
|
+
return prototypePollutionBlockList.indexOf(part) === -1
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* Converts flat objects whose keys use JSON path notation to nested objects.
|
|
685
|
+
*
|
|
686
|
+
* The input object is not mutated.
|
|
687
|
+
*
|
|
688
|
+
* @example
|
|
689
|
+
* { 'foo[bar][0]': 'baz' } -> { foo: { bar: [ 'baz' ] } }
|
|
690
|
+
*/
|
|
691
|
+
const expand = input => {
|
|
692
|
+
if (input === undefined || input === null) {
|
|
693
|
+
return input
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
const keys = Object.keys(input)
|
|
697
|
+
|
|
698
|
+
const result = {}
|
|
699
|
+
let resultPtr = result
|
|
700
|
+
|
|
701
|
+
for (let path of keys) {
|
|
702
|
+
const originalPath = path
|
|
703
|
+
if (path.indexOf('[') >= 0) {
|
|
704
|
+
path = path.replace(/\[/g, '.').replace(/]/g, '')
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
const parts = path.split('.')
|
|
708
|
+
|
|
709
|
+
const check = parts.filter(blocklistFilter)
|
|
710
|
+
|
|
711
|
+
if (check.length !== parts.length) {
|
|
712
|
+
return undefined
|
|
713
|
+
}
|
|
714
|
+
resultPtr = result
|
|
715
|
+
const lastIndex = parts.length - 1
|
|
716
|
+
|
|
717
|
+
for (let i = 0; i < parts.length; ++i) {
|
|
718
|
+
const part = parts[i]
|
|
719
|
+
if (i === lastIndex) {
|
|
720
|
+
if (Array.isArray(resultPtr)) {
|
|
721
|
+
resultPtr[+part] = input[originalPath]
|
|
722
|
+
} else {
|
|
723
|
+
resultPtr[part] = input[originalPath]
|
|
724
|
+
}
|
|
725
|
+
} else {
|
|
726
|
+
if (resultPtr[part] === undefined || resultPtr[part] === null) {
|
|
727
|
+
const nextPart = parts[i + 1]
|
|
728
|
+
if (/^\d+$/.test(nextPart)) {
|
|
729
|
+
resultPtr[part] = []
|
|
730
|
+
} else {
|
|
731
|
+
resultPtr[part] = {}
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
resultPtr = resultPtr[part]
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
return result
|
|
739
|
+
}
|
|
740
|
+
|
|
668
741
|
module.exports = {
|
|
669
742
|
contentEncoding,
|
|
670
743
|
dataEqual,
|
|
671
744
|
deleteHeadersField,
|
|
745
|
+
expand,
|
|
672
746
|
forEachHeader,
|
|
673
747
|
formatQueryValue,
|
|
674
748
|
headersArrayToObject,
|
package/lib/match_body.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const mapValues = require('lodash/mapValues')
|
|
4
3
|
const querystring = require('querystring')
|
|
5
4
|
|
|
6
5
|
const common = require('./common')
|
|
@@ -62,6 +61,14 @@ module.exports = function matchBody(options, spec, body) {
|
|
|
62
61
|
return common.dataEqual(spec, body)
|
|
63
62
|
}
|
|
64
63
|
|
|
64
|
+
function mapValues(object, cb) {
|
|
65
|
+
const keys = Object.keys(object)
|
|
66
|
+
for (const key of keys) {
|
|
67
|
+
object[key] = cb(object[key], key, object)
|
|
68
|
+
}
|
|
69
|
+
return object
|
|
70
|
+
}
|
|
71
|
+
|
|
65
72
|
/**
|
|
66
73
|
* Based on lodash issue discussion
|
|
67
74
|
* https://github.com/lodash/lodash/issues/1244
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"testing",
|
|
8
8
|
"isolation"
|
|
9
9
|
],
|
|
10
|
-
"version": "13.3.
|
|
10
|
+
"version": "13.3.6",
|
|
11
11
|
"author": "Pedro Teixeira <pedro.teixeira@gmail.com>",
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"debug": "^4.1.0",
|
|
26
26
|
"json-stringify-safe": "^5.0.1",
|
|
27
|
-
"lodash": "^4.17.21",
|
|
28
27
|
"propagate": "^2.0.0"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|
|
@@ -48,7 +47,7 @@
|
|
|
48
47
|
"prettier": "3.0.3",
|
|
49
48
|
"proxyquire": "^2.1.0",
|
|
50
49
|
"rimraf": "^3.0.0",
|
|
51
|
-
"semantic-release": "^
|
|
50
|
+
"semantic-release": "^22.0.5",
|
|
52
51
|
"sinon": "^15.0.1",
|
|
53
52
|
"sinon-chai": "^3.7.0",
|
|
54
53
|
"typescript": "^5.0.4"
|