Skip to content

Commit

Permalink
fix: revert breaking changes from v11.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Feb 16, 2020
1 parent a275769 commit 062c10e
Show file tree
Hide file tree
Showing 22 changed files with 176 additions and 330 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yaml
Expand Up @@ -121,5 +121,5 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [10, 12, 13]
node-version: [8, 10, 12, 13]
os: [macos-latest, ubuntu-latest, windows-latest]
7 changes: 1 addition & 6 deletions README.md
Expand Up @@ -1154,7 +1154,7 @@ For enabling any real HTTP requests (the default behavior):
nock.enableNetConnect()
```

You could allow real HTTP requests for certain host names by providing a string or a regular expression for the hostname, or a function that accepts the hostname and returns true or false:
You could allow real HTTP requests for certain host names by providing a string or a regular expression for the hostname:

```js
// Using a string
Expand All @@ -1163,11 +1163,6 @@ nock.enableNetConnect('amazon.com')
// Or a RegExp
nock.enableNetConnect(/(amazon|github)\.com/)

// Or a Function
nock.enableNetConnect(
host => host.includes('amazon.com') || host.includes('github.com')
)

http.get('http://www.amazon.com/')
http.get('http://github.com/')

Expand Down
9 changes: 8 additions & 1 deletion index.js
Expand Up @@ -29,7 +29,14 @@ Object.assign(module.exports, {
removeInterceptor,
disableNetConnect,
enableNetConnect,
cleanAll: removeAll,
// TODO-12.x Historically `nock.cleanAll()` has returned the nock global.
// The other global methods do not do this, so it's not clear this was
// deliberate or is even helpful. This shim is included for backward
// compatibility and should be replaced with an alias to `removeAll()`.
cleanAll() {
removeAll()
return module.exports
},
abortPendingRequests,
load,
loadDefs,
Expand Down
4 changes: 3 additions & 1 deletion lib/back.js
@@ -1,6 +1,7 @@
'use strict'

const assert = require('assert')
const _ = require('lodash')
const recorder = require('./recorder')
const {
activate,
Expand Down Expand Up @@ -60,7 +61,8 @@ function Back(fixtureName, options, nockedFn) {
)
}

if (typeof fixtureName !== 'string') {
// TODO-12.x: Replace with `typeof fixtureName === 'string'`.
if (!_.isString(fixtureName)) {
throw new Error('Parameter fixtureName must be a string')
}

Expand Down
9 changes: 6 additions & 3 deletions lib/common.js
Expand Up @@ -174,7 +174,8 @@ function stringifyRequest(options, body) {

function isContentEncoded(headers) {
const contentEncoding = headers['content-encoding']
return typeof contentEncoding === 'string' && contentEncoding !== ''
// TODO-12.x: Replace with `typeof contentEncoding === 'string'`.
return _.isString(contentEncoding) && contentEncoding !== ''
}

function contentEncoding(headers, encoder) {
Expand Down Expand Up @@ -363,7 +364,8 @@ function deleteHeadersField(headers, fieldNameToDelete) {
throw Error('headers must be an object')
}

if (typeof fieldNameToDelete !== 'string') {
// TODO-12.x: Replace with `typeof fieldNameToDelete !== 'string'`.
if (!_.isString(fieldNameToDelete)) {
throw Error('field name must be a string')
}

Expand Down Expand Up @@ -444,7 +446,8 @@ function formatQueryValue(key, value, stringFormattingFn) {
case value === undefined:
value = ''
break
case typeof value === 'string':
// TODO-12.x: Replace with `typeof value === 'string'`.
case _.isString(value):
if (stringFormattingFn) {
value = stringFormattingFn(value)
}
Expand Down
9 changes: 3 additions & 6 deletions lib/intercept.js
Expand Up @@ -8,6 +8,7 @@ const { InterceptedRequestRouter } = require('./intercepted_request_router')
const common = require('./common')
const { inherits } = require('util')
const http = require('http')
const _ = require('lodash')
const debug = require('debug')('nock.intercept')
const globalEmitter = require('./global_emitter')

Expand Down Expand Up @@ -49,17 +50,13 @@ let allowNetConnect
* @example
* // Enables real requests for url that matches google and amazon
* nock.enableNetConnect(/(google|amazon)/);
* @example
* // Enables real requests for url that includes google
* nock.enableNetConnect(host => host.includes('google'));
*/
function enableNetConnect(matcher) {
if (typeof matcher === 'string') {
// TODO-12.x: Replace with `typeof matcher === 'string'`.
if (_.isString(matcher)) {
allowNetConnect = new RegExp(matcher)
} else if (matcher instanceof RegExp) {
allowNetConnect = matcher
} else if (typeof matcher === 'function') {
allowNetConnect = { test: matcher }
} else {
allowNetConnect = /.*/
}
Expand Down

0 comments on commit 062c10e

Please sign in to comment.