Skip to content

Conversation

@renovate
Copy link
Contributor

@renovate renovate bot commented Sep 4, 2019

This PR contains the following updates:

Package Type Update Change
nock devDependencies major 10.0.6 -> 11.7.2

Release Notes

nock/nock

v11.7.2

Compare Source

Bug Fixes
  • Fix a regression due to Jest having different globals (#​1850) (c7363e5)

v11.7.1

Compare Source

Bug Fixes

v11.7.0

Compare Source

Features

v11.6.0

Compare Source

Features

v11.5.0

Compare Source

Features

v11.4.0

Compare Source

Features

v11.3.6

Compare Source

Bug Fixes

v11.3.5

Compare Source

Bug Fixes

v11.3.4

Compare Source

Bug Fixes

v11.3.3

Compare Source

Bug Fixes

v11.3.2

Compare Source

Upgrading from Nock 10 to Nock 11

Bug fixes and internal improvements

Nock 11 includes many under-the-hood improvements, including a fully offline
test suite and 100% test coverage. The codebase was also converted to ES6
syntax and formatted with Prettier. Leaning on the test coverage, some
substantial refactors have begun.

Many bug fixes are included. See the detailed changelog below or the
compare view for details.

Fabulous new features for developers
  1. The library ships with TypeScript definitions. (Added in v11.3)
  2. Add support for the http.request signatures added in Node 10.9
  3. Scopes can be filtered using the system environment or any external factor
    using e.g. .conditionally(() => true)
  4. In-flight modifications to headers are preserved in mock requests.
  5. Recorded mocks can be stringified using custom code in the afterRecord()
    post-processing hook. When afterRecord() returns a string, the
    recorder will no longer attempt to re-stringify it. (Added in v11.3)
  6. Reply functions passed to .reply() can now be async/promise-returning.
  7. Specifying reply headers, either via .reply() or .defaultReplyHeaders(),
    can now be done consistently using an object, Map, or flat array.
Breaking changes

For many developers no code changes will be needed. However, there are several
minor changes to the API, and it's possible that you will need to update your
code for Nock to keep working properly. It's unlikely that your tests will
falsely pass; what's more probable is that your tests will fail until the
necessary changes are made.

  1. Nock 11 requires Node 8 or later. Nock supports and tests all the "current"
    and "maintenance" versions of Node. As of now, that's Node 8, 10, and 12.

  2. In Nock 10, when reply() was invoked with a function, the return values were
    handled ambiguously depending on their types.

    Consider the following example:

    const scope = nock('http://example.com')
      .get('/')
      .reply(200, () => [500, 'hello world'])

    In Nock 10, the 200 was ignored, the 500 was interpreted as the status
    code, and the body would contain 'hello world'. This caused problems
    when the goal was to return a numeric array, so in Nock 11, the 200 is
    properly interpreted as the status code, and [500, 'hello world'] as the
    body.

    These are the correct calls for Nock 11:

    const scope = nock('http://example.com')
      .get('/')
      .reply(500, 'hello world')
    
    const scope = nock('http://example.com')
      .get('/')
      .reply(500, () => 'hello world')

    The .reply() method can be called with explicit arguments:

    .reply() // `statusCode` defaults to `200`.
    .reply(statusCode) // `responseBody` defaults to `''`.
    .reply(statusCode, responseBody) // `headers` defaults to `{}`.
    .reply(statusCode, responseBody, headers)

    It can be called with a status code and a function that returns an array:

    .reply(statusCode, (path, requestBody) => responseBody)
    .reply(statusCode, (path, requestBody) => responseBody, headers)

    Alternatively the status code can be included in the array:

    .reply((path, requestBody) => [statusCode])
    .reply((path, requestBody) => [statusCode, responseBody])
    .reply((path, requestBody) => [statusCode, responseBody, headers])
    .reply((path, requestBody) => [statusCode, responseBody], headers)

    .reply() can also be called with an async or promise-returning function. The
    signatures are identical, e.g.

    .reply(async (path, requestBody) => [statusCode, responseBody])
    .reply(statusCode, async (path, requestBody) => responseBody)

    Finally, an error-first callback can be used, e.g.:

    .reply((path, requestBody, cb) => cb(undefined, [statusCode, responseBody]))
    .reply(statusCode, (path, requestBody, cb) => cb(undefined, responseBody))
  3. In Nock 10, errors in user-provided reply functions were caught by Nock, and
    generated HTTP responses with status codes of 500. In Nock 11 these errors
    are not caught, and instead are re-emitted through the request, like any
    other error that occurs during request processing.

    Consider the following example:

    const scope = nock('http://example.com')
      .post('/echo')
      .reply(201, (uri, requestBody, cb) => {
        fs.readFile('cat-poems.txt', cb) // Error-first callback
      })

    When fs.readFile() errors in Nock 10, a 500 error was emitted. To get the
    same effect in Nock 11, the example would need to be rewritten to:

    const scope = nock('http://example.com')
      .post('/echo')
      .reply((uri, requestBody, cb) => {
        fs.readFile('cat-poems.txt', (err, contents) => {
          if (err) {
            cb([500, err.stack])
          } else {
            cb([201, contents])
          }
        })
      })
  4. When .reply() is invoked with something other than a whole number status
    code or a function, Nock 11 raises a new error Invalid ... value for status code.

  5. Callback functions provided to the .query method now receive the result of querystring.parse instead of qs.parse.

    In particular, querystring.parse does not interpret keys with JSON
    path notation:

    querystring.parse('foo[bar]=baz') // { "foo[bar]": 'baz' }
    qs.parse('foo[bar]=baz') // { foo: { bar: 'baz' } }
  6. In Nock 10, duplicate field names provided to the .query() method were
    silently ignored. We decided this was probably hiding unintentionally bugs
    and causing frustration with users. In Nock 11, attempts to provide query
    params more than once will throw a new error
    Query parameters have aleady been defined. This could happen by calling
    .query() twice, or by calling .query() after specifying a literal query
    string via the path.

    nock('http://example.com')
      .get('/path')
      .query({ foo: 'bar' })
      .query({ baz: 'qux' }) // <-- will throw
      .reply()
    
    nock('http://example.com')
      .get('/path?foo=bar')
      .query({ baz: 'qux' }) // <-- will throw
      .reply()
  7. Paths in Nock have always required a leading slash. e.g.

    const scope = nock('http://example.com')
      .get('/path')
      .reply()

    In Nock 10, if the leading slash was missing the mock would never match. In
    Nock 11, this raises an error.

  8. The reqheaders parameter should be provided as a plain object, e.g.
    nock('http://example.com', { reqheaders: { X-Foo: 'bar' }}). When the
    headers are specified incorrectly as e.g. { reqheaders: 1 }, Nock 10 would
    behave in unpredictable ways. In Nock 11, a new error
    Headers must be provided as an object is thrown.

    nock('http://example.com', { reqheaders: 1 })
      .get('/')
      .reply()
  9. In Nock 10, the ClientRequest instance wrapped the native on method
    and aliased once to it. In Nock 11, this been removed and request.once
    will correctly call registered listeners...once.

  10. In Nock 10, when the method was not specified in a call to nock.define(),
    the method would default to GET. In Nock 11, this raises an error.

  11. In very old versions of nock, recordings may include a response status
    code encoded as a string in the reply field. In Nock 10 these strings could
    be non-numeric. In Nock 11 this raises an error.

Updates to the mock surface
  1. For parity with a real response, a mock request correctly supports all
    the overrides to request.end(), including request.end(cb) in Node 12.
  2. For parity with a real response, errors from the .destroy() method
    are propagated correctly. (Added in v11.3)
  3. For parity with a real response, the .complete property is set when
    ending the response.
  4. For parity with a real Socket, the mock Socket has an unref() function
    (which does nothing).

If you discover bugs in this release, please open a bug report on the Nock repo. 🐛


Detailed changelog

##### BREAKING CHANGES
  • uncaught errors thrown inside of user provided reply functions, whether async or not, will no longer be caught, and will no longer generate a successful response with a status code of 500. Instead, the error will be emitted by the request just like any other unhandled error during the request processing.
  • The only argument passed to the Interceptor.query callback now receives the output from querystring.parse instead of qs.parse. This means that instead of nested objects the argument will be a flat object.
  • interceptor: Attempting to call Interceptor.query twice throws an error.
  • interceptor: Providing a duplicate search parameter to the query
    method throws an error instead of ignoring subsequent values.
  • Drop support for Node 6
Features
Bug Fixes
Code Refactoring

v11.3.1

Compare Source

v11.3.0

Compare Source

v11.2.0

Compare Source

v11.1.0

Compare Source

v11.0.0

Compare Source


Renovate configuration

📅 Schedule: "after 10pm every weekday,every weekend,before 5am every weekday" in timezone America/New_York.

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

♻️ Rebasing: Whenever PR becomes conflicted, or if you modify the PR title to begin with "rebase!".

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR has been generated by WhiteSource Renovate. View repository job log here.

@renovate renovate bot force-pushed the renovate/nock-11.x branch from 63d61fa to a16cba2 Compare September 4, 2019 03:38
@renovate renovate bot changed the title chore(deps): Update dependency nock to version 11.1.0 🌟 chore(deps): Update dependency nock to version 11.3.2 🌟 Sep 4, 2019
@renovate renovate bot changed the title chore(deps): Update dependency nock to version 11.3.2 🌟 chore(deps): Update dependency nock to version 11.3.2 🌟 Sep 4, 2019
@renovate renovate bot changed the title chore(deps): Update dependency nock to version 11.3.2 🌟 chore(deps): Update dependency nock to version 11.3.1 🌟 Sep 5, 2019
@renovate renovate bot force-pushed the renovate/nock-11.x branch 2 times, most recently from 37699cb to 61ad9b3 Compare September 6, 2019 02:17
@renovate renovate bot changed the title chore(deps): Update dependency nock to version 11.3.1 🌟 chore(deps): Update dependency nock to version 11.3.3 🌟 Sep 6, 2019
@renovate renovate bot force-pushed the renovate/nock-11.x branch from 61ad9b3 to 7f20ae9 Compare September 10, 2019 02:09
@renovate renovate bot changed the title chore(deps): Update dependency nock to version 11.3.3 🌟 chore(deps): update dependency nock to version 11.3.3 🌟 Sep 10, 2019
@renovate renovate bot force-pushed the renovate/nock-11.x branch from 7f20ae9 to 251eacb Compare September 12, 2019 02:10
@renovate renovate bot changed the title chore(deps): update dependency nock to version 11.3.3 🌟 chore(deps): Update dependency nock to version 11.3.3 🌟 Sep 12, 2019
@renovate renovate bot force-pushed the renovate/nock-11.x branch from 251eacb to 99411c4 Compare September 13, 2019 02:14
@renovate renovate bot changed the title chore(deps): Update dependency nock to version 11.3.3 🌟 chore(deps): Update dependency nock to version 11.3.4 🌟 Sep 13, 2019
@renovate renovate bot force-pushed the renovate/nock-11.x branch 4 times, most recently from 1009ea0 to 2957189 Compare September 20, 2019 02:14
@renovate renovate bot changed the title chore(deps): Update dependency nock to version 11.3.4 🌟 chore(deps): update dependency nock to version 11.3.4 🌟 Sep 20, 2019
@renovate renovate bot force-pushed the renovate/nock-11.x branch from 2957189 to 8b163dc Compare September 21, 2019 02:14
@renovate renovate bot changed the title chore(deps): update dependency nock to version 11.3.4 🌟 chore(deps): Update dependency nock to version 11.3.5 🌟 Sep 21, 2019
@renovate renovate bot force-pushed the renovate/nock-11.x branch 5 times, most recently from 9f493e3 to 94f9171 Compare October 2, 2019 02:08
@renovate renovate bot force-pushed the renovate/nock-11.x branch 3 times, most recently from a1e923d to aeaec40 Compare October 5, 2019 18:08
@renovate renovate bot force-pushed the renovate/nock-11.x branch 3 times, most recently from e3ecd0d to cb540ce Compare December 24, 2019 06:11
@renovate renovate bot changed the title chore(deps): update dependency nock to version 11.7.0 🌟 chore(deps): Update dependency nock to version 11.7.0 🌟 Dec 24, 2019
@renovate renovate bot force-pushed the renovate/nock-11.x branch 2 times, most recently from 79889c2 to babfa4b Compare December 27, 2019 03:14
@renovate renovate bot changed the title chore(deps): Update dependency nock to version 11.7.0 🌟 chore(deps): update dependency nock to version 11.7.0 🌟 Dec 27, 2019
@renovate renovate bot force-pushed the renovate/nock-11.x branch from babfa4b to c48a505 Compare December 30, 2019 07:11
@renovate renovate bot changed the title chore(deps): update dependency nock to version 11.7.0 🌟 chore(deps): Update dependency nock to version 11.7.0 🌟 Dec 30, 2019
@renovate renovate bot force-pushed the renovate/nock-11.x branch from c48a505 to 97aa782 Compare December 31, 2019 06:16
@renovate renovate bot changed the title chore(deps): Update dependency nock to version 11.7.0 🌟 chore(deps): update dependency nock to version 11.7.0 🌟 Dec 31, 2019
@renovate renovate bot force-pushed the renovate/nock-11.x branch from 97aa782 to 2c39058 Compare December 31, 2019 07:11
@renovate renovate bot changed the title chore(deps): update dependency nock to version 11.7.0 🌟 chore(deps): Update dependency nock to version 11.7.0 🌟 Dec 31, 2019
@renovate renovate bot force-pushed the renovate/nock-11.x branch from 2c39058 to 7df5f04 Compare January 3, 2020 03:15
@renovate renovate bot changed the title chore(deps): Update dependency nock to version 11.7.0 🌟 chore(deps): Update dependency nock to version 11.7.1 🌟 Jan 3, 2020
@renovate renovate bot force-pushed the renovate/nock-11.x branch 5 times, most recently from dc8322d to d8ff9e9 Compare January 9, 2020 03:12
@renovate renovate bot changed the title chore(deps): Update dependency nock to version 11.7.1 🌟 chore(deps): Update dependency nock to version 11.7.2 🌟 Jan 9, 2020
@renovate renovate bot force-pushed the renovate/nock-11.x branch 2 times, most recently from ae7b77f to 2fdbd20 Compare January 11, 2020 03:10
@renovate renovate bot changed the title chore(deps): Update dependency nock to version 11.7.2 🌟 chore(deps): Update dependency nock to version 11.7.2 🌟 Jan 11, 2020
@renovate renovate bot force-pushed the renovate/nock-11.x branch from 2fdbd20 to 6c12457 Compare January 11, 2020 06:14
@renovate renovate bot changed the title chore(deps): Update dependency nock to version 11.7.2 🌟 chore(deps): update dependency nock to version 11.7.2 🌟 Jan 13, 2020
@renovate
Copy link
Contributor Author

renovate bot commented Jan 13, 2020

Renovate Ignore Notification

As this PR has been closed unmerged, Renovate will ignore this upgrade and you will not receive PRs for any future 11.x releases. However, if you upgrade to 11.x manually then Renovate will then reenable updates for minor and patch updates automatically.

If this PR was closed by mistake or you changed your mind, you can simply rename this PR and you will soon get a fresh replacement PR opened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants