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

feat!: use URLPattern for request matching #2209

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@
"headers-polyfill": "^4.0.2",
"is-node-process": "^1.2.0",
"outvariant": "^1.4.2",
"path-to-regexp": "^6.2.0",
"strict-event-emitter": "^0.5.1",
"type-fest": "^4.9.0",
"urlpattern-polyfill": "^9.0.0",
"yargs": "^17.7.2"
},
"devDependencies": {
Expand Down
14 changes: 7 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/core/getResponse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ it('returns undefined given empty headers array', async () => {
it('returns undefined given no matching handlers', async () => {
expect(
await getResponse(
[http.get('/product', () => void 0)],
[http.get('*/product', () => void 0)],
new Request('http://localhost/user'),
),
).toBeUndefined()
Expand Down
23 changes: 23 additions & 0 deletions src/core/utils/matching/matchRequestUrl.node.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// @vite-environment node
import { Match, matchRequestUrl } from './matchRequestUrl'

test('does not throw on relative URLs in Node.js', () => {
expect(matchRequestUrl(new URL('http://localhost'), '/foo')).toEqual<Match>({
matches: false,
params: {},
})

expect(
matchRequestUrl(new URL('http://localhost/foo'), '/foo'),
).toEqual<Match>({
matches: false,
params: {},
})

expect(
matchRequestUrl(new URL('http://localhost/foo'), './foo'),
).toEqual<Match>({
matches: false,
params: {},
})
})
Loading
Loading