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

Interceptors don't match when used with different order "when using filteringScope option" #1818

Closed
salmanm opened this issue Nov 20, 2019 · 3 comments · Fixed by #1819
Closed
Labels

Comments

@salmanm
Copy link
Contributor

salmanm commented Nov 20, 2019

What is the expected behavior?

Interceptors should match correct request even when using filteringScope option

What is the actual behavior?

Typically interceptors work in any order. However, when using filteringScope option, they misbehave and don't match.

How to reproduce the issue

Take the following for example.

  nock('http://some.test', {
    filteringScope: scope => true,
  })
  .get('/path1?query=1')
  .reply(200, 'response for path1/query1')
  .get('/path2?query=2')
  .reply(200, 'response for path2/query2')

Here, if I make the request for /path2?query=2 first, it fails. Because the filteringScope returns true and it tries to match the path of /path2?query=2 against the first interceptor.

Possible solution

Here we return interceptors as soon as we find the one with filteringScope option. By doing this, we skip setting interceptor.__nock_filteredScope on the "actual" interceptor that should have been matched. Hence, if we return after the inner loop is over, then that should work.

Instead of RunKit, I'm opening a PR with two test cases to demonstrate the problem.

Having problem producing a test case? Try and ask the community for help. If the test case cannot be reproduced, the Nock community might not be able to help you.

Does the bug have a test case?

Versions

Software Version(s)
Nock latest
Node 10
TypeScript -
@paulmelnikow
Copy link
Member

Hi, thanks for the report and the PRR!

I think this is related to the failing tests I added in #1720, right?

@salmanm
Copy link
Contributor Author

salmanm commented Nov 20, 2019

O yes, didn't notice that PR. Yes looks like its one of those cases.

@nockbot
Copy link
Collaborator

nockbot commented Jan 3, 2020

🎉 This issue has been resolved in version 11.7.1 🎉

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 a pull request may close this issue.

3 participants