-
Notifications
You must be signed in to change notification settings - Fork 88
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
Regex path matching issue #96
Comments
Hi @chrisribe! I've just moved this to a separate issue since the previous one was resolved. Yes, if you want to use regexes you do need to provide a real regex object. Any strings passed to Your example looks correct though. Can you share some specific patterns that aren't working for you, and the requests that they're failing to match? |
Thanks for the reply and new issue for this :) My example test case that does not match properly. Code that does not match
|
That I can explain easily: If you want to match against the query string, you need do so explicitly, for example: server.forGet(/(.*)w3schools.com\/lib\/my-learning.js/)
// Either:
.withExactQuery('?v=1.0.9')
// Or:
.withQuery({ v: '1.0.9' })
.thenReply(200, 'There is a match !'); Does that make sense? I can see how this is a bit surprising, especially since we include the rest of the base domain here nowadays. It's tricky to change backward compatibly though, and for non-regex cases with exact string you generally do want matching to work like this... I'll keep an eye on that and see if I can improve this in a future major version bump. |
Ah that would explain it ! Yes this is very surprising as I was expecting that passing a regex would simply match on that for the full url. Any way to regex match on the full url and not use Like if I want to match on certain query parameter patterns |
I did find this showing all query param matchers do not support RegEx at all :( |
Yes, it's not possible to do query matching by regex right now. PRs very welcome though! It should be fairly easy to add a Alternatively, it might make sense to extend If you're interested in adding that, I'd suggest starting by writing a couple of tests for it, then exploring the existing matcher definition implementations you can find defined around here: mockttp/src/rules/base-rule-builder.ts Lines 136 to 144 in 0d586c5
|
Hello,
I was looking at allowing different RegEx patterns in the url matching.
RegEx test cases
I see in the test cases you only run tests with direct regex expressions and not strings.
await server.get(/.*.txt/).thenReply(200, 'Fake file');
Tried to create a regex pattern via new RegExp("some regex pattern string") but I am having match issues.
Any tips ?
Originally posted by @chrisribe in #9 (comment)
The text was updated successfully, but these errors were encountered: