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

Document various URL patterns (colon, asterisk etc.) #2203

Closed
silvenon opened this issue Jul 9, 2024 Discussed in #2202 · 3 comments
Closed

Document various URL patterns (colon, asterisk etc.) #2203

silvenon opened this issue Jul 9, 2024 Discussed in #2202 · 3 comments

Comments

@silvenon
Copy link

silvenon commented Jul 9, 2024

In #2202 it took me a while to figure out how to use MSW with SuperTest. It's making requests to random ports, which MSW is reporting as warnings/errors because they hadn't been intercepted. The goal is to tell MSW to ignore them, because those are requests to our own app.

It's clear that MSW has a parameter component of the URL preceded by the colon, but it seems to also supports an asterisk as a catch-all, which is what I was looking for in this case. However, I seem to have unfortunately combined both of them by preceding the asterisk with the colon and achieved a result that I didn't understand 😬

Luckily, after removing the colon everything worked as expected. I believe URL patterns should be documented in a way that makes it clear to people how to deal with situations like SuperTest.

Btw, did I stumble upon a bug? I guess URL matching can't really recognize ports vs. params when the URL is not finished.

@kettanaito
Copy link
Member

Hi, @silvenon. Thanks for raising this!

I believe we do mention the documentation for it. MSW uses a package called path-to-regexp, which has become the standard for path matching in JavaScript (used in Express, lies in the foundation of the upcoming URLPattern standard API).

Screenshot 2024-07-09 at 16 35 33

Please read that package's README to learn about the supported special tokens when defining paths. Thanks!

@kettanaito
Copy link
Member

Btw, did I stumble upon a bug? I guess URL matching can't really recognize ports vs. params when the URL is not finished.

This does sound like a bug though. Can you please open a new issue for this?

@silvenon
Copy link
Author

silvenon commented Jul 9, 2024

Ah, indeed, there it is, I missed it! 🙂

I raised the wildcard bug separately in #2204 if anyone wants to follow.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants