Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update/clarify interceptor.reply param juggling. #1520

Merged
merged 21 commits into from
May 20, 2019

Commits on May 1, 2019

  1. chore: update/clarify interceptor.reply param juggling.

    Based on conversation https://github.com/nock/nock/pull/1517/files#r280139478.
    
    The `arguments.length <= 2` was confusing/misleading, and clearing the
    `rawHeaders` clarifies the method's intention to anyone digging around,
    plus reduces the changes for bugs in the future.
    mastermatt committed May 1, 2019
    Configuration menu
    Copy the full SHA
    c87fa52 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    9b92974 View commit details
    Browse the repository at this point in the history

Commits on May 5, 2019

  1. Configuration menu
    Copy the full SHA
    6ba0f5c View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    4cae0ba View commit details
    Browse the repository at this point in the history

Commits on May 6, 2019

  1. Configuration menu
    Copy the full SHA
    be2b310 View commit details
    Browse the repository at this point in the history
  2. Add statusCodeInt helper too common.

    This commit only includes the implementation and tests.
    Callers are to follow, but I didn’t want to muddy commit history.
    mastermatt committed May 6, 2019
    Configuration menu
    Copy the full SHA
    14fe6d0 View commit details
    Browse the repository at this point in the history
  3. Simplify Interceptor.reply signature.

    Includes breaking changes.
    
    - When a status code is provided followed by a function, the function returns the body. No magic.
    - When a function is provided on its own, it _MUST_ return an array of `status, [body, [headers]]`. Again, no magic.
    
    This change uses errors to enforce the following two signatures:
    `.reply(status, [body, [headers]])` where `body` is any of the existing types that can result in a scalar value.
    `.reply(() => [status, body = ‘’, headers = {}])` where the callback is called using the existing mechanics.
    
    #### Breaking changes
    
    - There is no longer a default value for the response status code. It must
    be provided as the first arg of `reply` or the first element in the
    returned array if using the single-function style.
      - `.reply()` will now throw an error
    
    - Status code args will throw an error if they cannot be cast to ints.
    
    - The single-function style callback **MUST** return an array with a
      length of 1-3 or else an error is thrown.
    
    - If **NOT** using the single-function style callback, the resulting body
      will never be treated as a special value for status code or headers,
      it will always result to the responses body value.
      - `reply(200, () => [400, ‘foo’])`
        - **previous result** status: 400 body: ‘foo’
        - **new result** status: 200 body: “[400, ‘foo’]”
      - `reply(200, () => [400])`
        - **previous result** status: 400 body: “[400]”
        - **new result** status: 200 body: “[400]”
    mastermatt committed May 6, 2019
    Configuration menu
    Copy the full SHA
    9913f68 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    7d1a3be View commit details
    Browse the repository at this point in the history
  5. Bugfix Interceptor.filteringPath

    Calling `filteringPath` on the intercept instance was broken as the
    transform fn set on the scope had the wrong name. Found when looking at
    Uncovered lines in coveralls.
    mastermatt committed May 6, 2019
    Configuration menu
    Copy the full SHA
    5baf9ed View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    833dae2 View commit details
    Browse the repository at this point in the history

Commits on May 8, 2019

  1. Configuration menu
    Copy the full SHA
    2ee5821 View commit details
    Browse the repository at this point in the history
  2. Remove statusCodeInt helper.

    Prefer to not cast and instead have a hard requirement for the arg to already be an int.
    Allow status code to not be provided and default to 200 again.
    mastermatt committed May 8, 2019
    Configuration menu
    Copy the full SHA
    f6f1f0b View commit details
    Browse the repository at this point in the history
  3. Allow native falsy values as body.

    While `false` and `null` are falsy, they are valid JSON value so they
    should be returned as a strings that JSON.parse would convert back to
    native values.
    
    Should fix nock#1446
    mastermatt committed May 8, 2019
    Configuration menu
    Copy the full SHA
    b2ad0ad View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    af42783 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    cb272d4 View commit details
    Browse the repository at this point in the history
  6. Bugfix?

    `a` is not a local var.
    mastermatt committed May 8, 2019
    Configuration menu
    Copy the full SHA
    13f347b View commit details
    Browse the repository at this point in the history
  7. CR feedback. Separate two interceptor reply fns.

    Use different attribute names for the reply functions that return a body
    vs return an array for the whole response (dynamic).
    
    Rejigger RequestOverrider.end to return early based which flow is used.
    It would be nice if this method was split up into more pure functions
    to reduce the complexity.
    mastermatt committed May 8, 2019
    Configuration menu
    Copy the full SHA
    c491360 View commit details
    Browse the repository at this point in the history
  8. Add test to cover a JSON array for the body.

    This is a regression test for nock#1208.
    mastermatt committed May 8, 2019
    Configuration menu
    Copy the full SHA
    98eb511 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    14cf473 View commit details
    Browse the repository at this point in the history

Commits on May 19, 2019

  1. Add a note to the readme

    paulmelnikow committed May 19, 2019
    Configuration menu
    Copy the full SHA
    7043064 View commit details
    Browse the repository at this point in the history

Commits on May 20, 2019

  1. CR feedback updates.

    mastermatt committed May 20, 2019
    Configuration menu
    Copy the full SHA
    f317877 View commit details
    Browse the repository at this point in the history