nock 11.7.1 → 11.7.2

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/back.js CHANGED
@@ -71,7 +71,7 @@ function Back(fixtureName, options, nockedFn) {
71
71
  } else if (arguments.length === 2) {
72
72
  // If 2nd parameter is a function then `options` has been omitted
73
73
  // otherwise `options` haven't been omitted but `nockedFn` was.
74
- if (options instanceof Function) {
74
+ if (typeof options === 'function') {
75
75
  nockedFn = options
76
76
  options = {}
77
77
  }
@@ -89,7 +89,7 @@ function Back(fixtureName, options, nockedFn) {
89
89
  debug('context:', context)
90
90
 
91
91
  // If nockedFn is a function then invoke it, otherwise return a promise resolving to nockDone.
92
- if (nockedFn instanceof Function) {
92
+ if (typeof nockedFn === 'function') {
93
93
  nockedFn.call(context, nockDone)
94
94
  } else {
95
95
  return Promise.resolve({ nockDone, context })
@@ -170,7 +170,7 @@ const record = {
170
170
  if (context.isRecording) {
171
171
  let outputs = recorder.outputs()
172
172
 
173
- if (options.afterRecord instanceof Function) {
173
+ if (typeof options.afterRecord === 'function') {
174
174
  outputs = options.afterRecord(outputs)
175
175
  }
176
176
 
package/lib/common.js CHANGED
@@ -315,7 +315,7 @@ const noDuplicatesHeaders = new Set([
315
315
  */
316
316
  function addHeaderLine(headers, name, value) {
317
317
  let values // code below expects `values` to be an array of strings
318
- if (value instanceof Function) {
318
+ if (typeof value === 'function') {
319
319
  // Function values are evaluated towards the end of the response, before that we use a placeholder
320
320
  // string just to designate that the header exists. Useful when `Content-Type` is set with a function.
321
321
  values = [value.name]
@@ -476,7 +476,7 @@ function isStream(obj) {
476
476
  obj &&
477
477
  typeof obj !== 'string' &&
478
478
  !Buffer.isBuffer(obj) &&
479
- obj.setEncoding instanceof Function
479
+ typeof obj.setEncoding === 'function'
480
480
  )
481
481
  }
482
482
 
@@ -500,7 +500,7 @@ function normalizeClientRequestArgs(input, options, cb) {
500
500
  input = null
501
501
  }
502
502
 
503
- if (options instanceof Function) {
503
+ if (typeof options === 'function') {
504
504
  cb = options
505
505
  options = input || {}
506
506
  } else {
@@ -113,7 +113,11 @@ class InterceptedRequestRouter {
113
113
  }
114
114
  this.requestBodyBuffers.push(buffer)
115
115
  }
116
- if (callback instanceof Function) {
116
+ // can't use instanceof Function because some test runners
117
+ // run tests in vm.runInNewContext where Function is not same
118
+ // as that in the current context
119
+ // https://github.com/nock/nock/pull/1754#issuecomment-571531407
120
+ if (typeof callback === 'function') {
117
121
  callback()
118
122
  }
119
123
  } else {
@@ -131,17 +135,17 @@ class InterceptedRequestRouter {
131
135
  debug('req.end')
132
136
  const { req } = this
133
137
 
134
- if (chunk instanceof Function) {
138
+ if (typeof chunk === 'function') {
135
139
  callback = chunk
136
140
  chunk = null
137
- } else if (encoding instanceof Function) {
141
+ } else if (typeof encoding === 'function') {
138
142
  callback = encoding
139
143
  encoding = null
140
144
  }
141
145
 
142
146
  if (!req.aborted && !this.playbackStarted) {
143
147
  req.write(chunk, encoding, () => {
144
- if (callback instanceof Function) {
148
+ if (typeof callback === 'function') {
145
149
  callback()
146
150
  }
147
151
  this.startPlayback()
@@ -110,7 +110,7 @@ module.exports = class Interceptor {
110
110
 
111
111
  reply(statusCode, body, rawHeaders) {
112
112
  // support the format of only passing in a callback
113
- if (statusCode instanceof Function) {
113
+ if (typeof statusCode === 'function') {
114
114
  if (arguments.length > 1) {
115
115
  // It's not very Javascript-y to throw an error for extra args to a function, but because
116
116
  // of legacy behavior, this error was added to reduce confusion for those migrating.
@@ -126,7 +126,7 @@ module.exports = class Interceptor {
126
126
  }
127
127
 
128
128
  this.statusCode = statusCode || 200
129
- if (body instanceof Function) {
129
+ if (typeof body === 'function') {
130
130
  this.replyFunction = body
131
131
  body = null
132
132
  }
@@ -215,7 +215,7 @@ module.exports = class Interceptor {
215
215
  }
216
216
 
217
217
  if (reqHeader !== undefined && header !== undefined) {
218
- if (reqHeader instanceof Function) {
218
+ if (typeof reqHeader === 'function') {
219
219
  return reqHeader(header)
220
220
  } else if (common.matchStringOrRegexp(header, reqHeader)) {
221
221
  return true
@@ -250,7 +250,7 @@ module.exports = class Interceptor {
250
250
 
251
251
  const requestMatchesFilter = ({ name, value: predicate }) => {
252
252
  const headerValue = req.getHeader(name)
253
- if (predicate instanceof Function) {
253
+ if (typeof predicate === 'function') {
254
254
  return predicate(headerValue)
255
255
  } else {
256
256
  return common.matchStringOrRegexp(headerValue, predicate)
@@ -317,7 +317,7 @@ module.exports = class Interceptor {
317
317
  matchKey = common.normalizeOrigin(proto, options.host, options.port)
318
318
  }
319
319
 
320
- if (this.uri instanceof Function) {
320
+ if (typeof this.uri === 'function') {
321
321
  matches =
322
322
  common.matchStringOrRegexp(matchKey, this.basePath) &&
323
323
  // This is a false positive, as `uri` is not bound to `this`.
@@ -397,7 +397,7 @@ module.exports = class Interceptor {
397
397
  debug('Interceptor queries: %j', this.queries)
398
398
  debug(' Request queries: %j', reqQueries)
399
399
 
400
- if (this.queries instanceof Function) {
400
+ if (typeof this.queries === 'function') {
401
401
  return this.queries(reqQueries)
402
402
  }
403
403
 
@@ -458,7 +458,7 @@ module.exports = class Interceptor {
458
458
  return this
459
459
  }
460
460
 
461
- if (queries instanceof Function) {
461
+ if (typeof queries === 'function') {
462
462
  this.queries = queries
463
463
  return this
464
464
  }
package/lib/match_body.js CHANGED
@@ -26,7 +26,7 @@ module.exports = function matchBody(options, spec, body) {
26
26
 
27
27
  // try to transform body to json
28
28
  let json
29
- if (typeof spec === 'object' || spec instanceof Function) {
29
+ if (typeof spec === 'object' || typeof spec === 'function') {
30
30
  try {
31
31
  json = JSON.parse(body)
32
32
  } catch (err) {
@@ -39,7 +39,7 @@ module.exports = function matchBody(options, spec, body) {
39
39
  }
40
40
  }
41
41
 
42
- if (spec instanceof Function) {
42
+ if (typeof spec === 'function') {
43
43
  return spec.call(options, body)
44
44
  }
45
45
 
@@ -270,7 +270,7 @@ function playbackInterceptor({
270
270
 
271
271
  // Evaluate functional headers.
272
272
  common.forEachHeader(response.rawHeaders, (value, fieldName, i) => {
273
- if (value instanceof Function) {
273
+ if (typeof value === 'function') {
274
274
  response.rawHeaders[i + 1] = value(req, response, responseBody)
275
275
  }
276
276
  })
package/lib/recorder.js CHANGED
@@ -344,10 +344,10 @@ function record(recOptions) {
344
344
  const oldEnd = req.end
345
345
  req.end = function(chunk, encoding, callback) {
346
346
  debug('req.end')
347
- if (chunk instanceof Function) {
347
+ if (typeof chunk === 'function') {
348
348
  callback = chunk
349
349
  chunk = null
350
- } else if (encoding instanceof Function) {
350
+ } else if (typeof encoding === 'function') {
351
351
  callback = encoding
352
352
  encoding = null
353
353
  }
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "testing",
8
8
  "isolation"
9
9
  ],
10
- "version": "11.7.1",
10
+ "version": "11.7.2",
11
11
  "author": "Pedro Teixeira <pedro.teixeira@gmail.com>",
12
12
  "repository": {
13
13
  "type": "git",
@@ -32,7 +32,7 @@
32
32
  "assert-rejects": "^1.0.0",
33
33
  "chai": "^4.1.2",
34
34
  "dirty-chai": "^2.0.1",
35
- "dtslint": "^1.0.2",
35
+ "dtslint": "^2.0.2",
36
36
  "eslint": "^6.0.0",
37
37
  "eslint-config-prettier": "^6.0.0",
38
38
  "eslint-config-standard": "^14.0.0",
@@ -51,7 +51,7 @@
51
51
  "request": "^2.83.0",
52
52
  "rimraf": "^3.0.0",
53
53
  "semantic-release": "^16.0.0-beta.22",
54
- "sinon": "^7.5.0",
54
+ "sinon": "^8.0.0",
55
55
  "sinon-chai": "^3.3.0",
56
56
  "superagent": "^5.0.2",
57
57
  "tap": "^14.0.0"