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
Port wildcard support for nockBack mocks #1494
Comments
Implementation-wise this feature revolves less around Line 58 in edce256
Unfortunately, ports are never directly compared when a request is being compared for a match. They are concatenated into a "base path" string that is then compared against with other whole strings or regex. So there are some non-trivial, underlying implementation details that would need to be addressed before this feature could be rolled out. This first question to ask is probably: what should the user interface be for this feature? I can think of a couple options:
I'll leave this comment as an open question. Personally, I'm on the fence. I think I dislike the asterisk the most, at that point just provide a regex. Adding an option to |
Is it possible that this use case could be handled using Basically it lets you write a function to handle host matching. It's designed for wildcard hostnames, though I think it already works for ports. I'm open to redesigning / improving the API including breaking changes and happy to discuss that as well. To be honest, I think |
Is it currently possible to use |
Indeed not. That part would need to be added. |
This would be a great feature |
Anyone have a clue how one would go about adding a filteringScope on nockBack? I'm having a hard time with this code base 😬 |
ping |
@simlu This is the solution that we ended up building in adidas for this problem: https://www.npmjs.com/package/nockback-harder |
@kibertoad would you be interested in contributing it back to nock? I'll work on moving the recording logic into its own |
@gr2m I would be happy to. Please ping me when there will be something I could be moving it to. |
Will do |
ummm.. is this issue dead? 🤔 |
The problem is that the code base is really hard to work with. So I couldn't figure out where the appropriate place to add this feature was But the request is very much still relevant |
Context
Currently you need to explicitly manage port on which your test application is running when executing nockBack mocks so that recorded port matches the one you are currently running application on. This is a major inconvenience since
supertest
randomizes execution port.It should be possible to specify wildcard port (*) that would match request against any possible port value or possibly its absence. Alternatively a parameter that would accept any port or its absence when no port is specified could also be a solution.
Alternatives
It is possible to manually launch and stop server for application under test that would be listening to specific port, but starting and stopping server manually is both introducing additional boilerplate and is not even that easy when you are executing multiple tests in parallel (as then you have to solve port collision problem yourself).
If the feature request is accepted, would you be willing to submit a PR?
Yes
The text was updated successfully, but these errors were encountered: