-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove dependency on path-to-regexp (#12001)
Co-authored-by: Erika <[email protected]>
- Loading branch information
1 parent
8d4eb95
commit 9be3e1b
Showing
5 changed files
with
197 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Remove dependency on path-to-regexp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
import * as assert from 'node:assert/strict'; | ||
import { describe, it } from 'node:test'; | ||
|
||
import { getRouteGenerator } from '../../../dist/core/routing/manifest/generator.js'; | ||
|
||
describe('routing - generator', () => { | ||
[ | ||
{ | ||
routeData: [], | ||
trailingSlash: 'never', | ||
params: {}, | ||
path: '/', | ||
}, | ||
{ | ||
routeData: [], | ||
trailingSlash: 'always', | ||
params: {}, | ||
path: '/', | ||
}, | ||
{ | ||
routeData: [[{ spread: false, content: 'test', dynamic: false }]], | ||
trailingSlash: 'never', | ||
params: {}, | ||
path: '/test', | ||
}, | ||
{ | ||
routeData: [[{ spread: false, content: 'test', dynamic: false }]], | ||
trailingSlash: 'always', | ||
params: {}, | ||
path: '/test/', | ||
}, | ||
{ | ||
routeData: [[{ spread: false, content: 'test', dynamic: false }]], | ||
trailingSlash: 'always', | ||
params: { foo: 'bar' }, | ||
path: '/test/', | ||
}, | ||
{ | ||
routeData: [[{ spread: false, content: 'foo', dynamic: true }]], | ||
trailingSlash: 'always', | ||
params: { foo: 'bar' }, | ||
path: '/bar/', | ||
}, | ||
{ | ||
routeData: [[{ spread: false, content: 'foo', dynamic: true }]], | ||
trailingSlash: 'never', | ||
params: { foo: 'bar' }, | ||
path: '/bar', | ||
}, | ||
{ | ||
routeData: [[{ spread: true, content: '...foo', dynamic: true }]], | ||
trailingSlash: 'never', | ||
params: {}, | ||
path: '/', | ||
}, | ||
{ | ||
routeData: [ | ||
[ | ||
{ spread: true, content: '...foo', dynamic: true }, | ||
{ spread: false, content: '-', dynamic: false }, | ||
{ spread: true, content: '...bar', dynamic: true }, | ||
], | ||
], | ||
trailingSlash: 'never', | ||
params: { foo: 'one', bar: 'two' }, | ||
path: '/one-two', | ||
}, | ||
{ | ||
routeData: [ | ||
[ | ||
{ spread: true, content: '...foo', dynamic: true }, | ||
{ spread: false, content: '-', dynamic: false }, | ||
{ spread: true, content: '...bar', dynamic: true }, | ||
], | ||
], | ||
trailingSlash: 'never', | ||
params: {}, | ||
path: '/-', | ||
}, | ||
{ | ||
routeData: [ | ||
[{ spread: true, content: '...foo', dynamic: true }], | ||
[{ spread: true, content: '...bar', dynamic: true }], | ||
], | ||
trailingSlash: 'never', | ||
params: { foo: 'one' }, | ||
path: '/one', | ||
}, | ||
{ | ||
routeData: [ | ||
[{ spread: false, content: 'fix', dynamic: false }], | ||
[{ spread: true, content: '...foo', dynamic: true }], | ||
[{ spread: true, content: '...bar', dynamic: true }], | ||
], | ||
trailingSlash: 'never', | ||
params: { foo: 'one' }, | ||
path: '/fix/one', | ||
}, | ||
{ | ||
routeData: [ | ||
[{ spread: false, content: 'fix', dynamic: false }], | ||
[{ spread: true, content: '...foo', dynamic: true }], | ||
[{ spread: true, content: '...bar', dynamic: true }], | ||
], | ||
trailingSlash: 'always', | ||
params: { foo: 'one' }, | ||
path: '/fix/one/', | ||
}, | ||
{ | ||
routeData: [ | ||
[{ spread: false, content: 'fix', dynamic: false }], | ||
[{ spread: true, content: '...foo', dynamic: true }], | ||
[{ spread: true, content: '...bar', dynamic: true }], | ||
], | ||
trailingSlash: 'never', | ||
params: { foo: 'one', bar: 'two' }, | ||
path: '/fix/one/two', | ||
}, | ||
{ | ||
routeData: [ | ||
[{ spread: false, content: 'fix', dynamic: false }], | ||
[{ spread: true, content: '...foo', dynamic: true }], | ||
[{ spread: true, content: '...bar', dynamic: true }], | ||
], | ||
trailingSlash: 'never', | ||
params: { foo: 'one&two' }, | ||
path: '/fix/one&two', | ||
}, | ||
{ | ||
routeData: [ | ||
[{ spread: false, content: 'fix', dynamic: false }], | ||
[{ spread: false, content: 'page', dynamic: true }], | ||
], | ||
trailingSlash: 'never', | ||
params: { page: 1 }, | ||
path: '/fix/1', | ||
}, | ||
].forEach(({ routeData, trailingSlash, params, path }) => { | ||
it(`generates ${path}`, () => { | ||
const generator = getRouteGenerator(routeData, trailingSlash); | ||
assert.equal(generator(params), path); | ||
}); | ||
}); | ||
|
||
it('should throw an error when a dynamic parameter is missing', () => { | ||
const generator = getRouteGenerator( | ||
[[{ spread: false, content: 'foo', dynamic: true }]], | ||
'never', | ||
); | ||
assert.throws(() => generator({}), TypeError); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.