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

feat(requestoverrider): Add method property to mocked requests #1561

Merged
merged 3 commits into from May 21, 2019

Conversation

mrijke
Copy link
Contributor

@mrijke mrijke commented May 19, 2019

Mocked requests were missing the 'method' property on them.

Added a testcase to the test_request_overrider testsuite.

@gr2m
Copy link
Member

gr2m commented May 19, 2019

Hey Maarten,

thanks for the pull request!

It would be very helpful if you first committed and pushed the test only, so we can directly see that it fails. Once the build failed, push the fix. It takes a little longer, but it’s very helpful for maintainers to review

Example

image

@paulmelnikow
Copy link
Member

Hi! Thanks for the PR. I may not have understood #1558.

Is adding method to req a behavior that is specific to superagent, or is it something that node's http module does? In general, Nock should do the standard thing, not implement workarounds and special behaviors for individual libraries.

As I mentioned at #1558:

A note on the testing strategy: we're moving away from preventing regression of integration problems using wide-bracket integration tests (#1427). So we should instead add a test which isolates the specific client behavior, and be added to the client-facing tests in https://github.com/nock/nock/blob/beta/tests/test_request_overrider.js.

The integration test can (and even should) be used to confirm the fix at the time of the change, but won't be kept in the main nock codebase.

So this will also need a regression test which isolates the specific client behavior, that can be kept in place of the one added here based on superagent.

@mrijke
Copy link
Contributor Author

mrijke commented May 19, 2019

@gr2m OK no problem, I'll rebase and split the commits.

@paulmelnikow: I'm not extremely familiar with node's http module, but as far as I can see this method property is something explicitly added by superagent (see their types).
I'm using this in my app to handle error responses differently, based on the method that was used. I honestly wasn't aware that it wasn't a default thing until that part of my code didn't work in a testcase in which I used nock.
I've added a regression testcase in my commit, as suggested by @gr2m I will split it in two commits. Is this what you meant by this, or am I misunderstanding something? You mention isolating client specific behavior, and since I think superagent is the only client doing this (at least not node's http module), I assume this test case is enough?

@mrijke mrijke force-pushed the feat-1558/SuperagentMethodOnRequest branch 2 times, most recently from 14e0095 to e574609 Compare May 19, 2019 21:00
@paulmelnikow
Copy link
Member

paulmelnikow commented May 19, 2019

Not sure I understand why those type defs are written the way they are, though fortunately, it doesn't seem like the method property is specific to superagent:

> require('http').request('http://www.google.com').method
'GET'

Added: And not so with Nock:

> const nock = require('.')
undefined
> const scope = nock('http://google.com').get('/').reply()
undefined
> require('http').request('http://google.com/').method
undefined

@mrijke
Copy link
Contributor Author

mrijke commented May 20, 2019

@paulmelnikow you're right... I was trying it out in runkit while nock was still mocking things, so I didn't see it...
How would you like me to proceed? I can turn this PR into something generic for http instead, removing all mentions of superagent, and keep the testcase but use http instead.

Add a testcase to ensure mocked requests have the 'method' property defined.
Mocked requests were missing the 'method' property on them.
@mrijke mrijke force-pushed the feat-1558/SuperagentMethodOnRequest branch 2 times, most recently from e962d41 to f41ffec Compare May 20, 2019 07:50
@mrijke mrijke changed the title feat(requestoverrider): Add method property to mocked requests from superagent feat(requestoverrider): Add method property to mocked requests May 20, 2019
Copy link
Member

@paulmelnikow paulmelnikow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for me! Left a couple minor tweaks. Thanks so much!

tests/test_request_overrider.js Outdated Show resolved Hide resolved
tests/test_request_overrider.js Show resolved Hide resolved
Improve testcase by suggestion of @paulmelnikow

Co-Authored-By: Paul Melnikow <github@paulmelnikow.com>
@paulmelnikow paulmelnikow merged commit 4857ae5 into nock:beta May 21, 2019
@paulmelnikow
Copy link
Member

🙌🏻

@nockbot
Copy link
Collaborator

nockbot commented May 21, 2019

🎉 This PR is included in version 11.0.0-beta.16 🎉

The release is available on:

Your semantic-release bot 📦🚀

@nockbot
Copy link
Collaborator

nockbot commented Aug 12, 2019

🎉 This PR is included in version 11.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants