Skip to content

Commit 862a7a6

Browse files
committed
test: support arbitrary wildcard patterns in mock routes
1 parent 9d39380 commit 862a7a6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

test/fixtures/mock-routes.cjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -599,10 +599,10 @@ function matchRoute(url) {
599599
* @returns {boolean}
600600
*/
601601
function urlMatchesPattern(url, pattern) {
602-
// Convert "https://example.com/**" to a prefix check
603-
if (pattern.endsWith('/**')) {
604-
const prefix = pattern.slice(0, -2)
605-
return url.startsWith(prefix)
602+
// Support wildcard patterns (e.g. https://*-dsn.algolia.net/**)
603+
if (pattern.includes('*')) {
604+
const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*')
605+
return new RegExp(`^${escaped}$`).test(url)
606606
}
607607
return url === pattern
608608
}

0 commit comments

Comments
 (0)