nock 13.3.4 → 13.3.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/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
- - `headers` - the headers of the reply
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):
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.4",
10
+ "version": "13.3.5",
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": "^21.0.2",
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"