@@ -4,46 +4,46 @@ import * as assert from 'uvu/assert';
4
4
import { exec } from '../../src/router.js' ;
5
5
6
6
function execPath ( path , pattern , opts ) {
7
- return exec ( path , pattern , { path, query : { } , params : { } , ...( opts || { } ) } ) ;
7
+ return exec ( path , pattern , { path, searchParams : { } , pathParams : { } , ...( opts || { } ) } ) ;
8
8
}
9
9
10
10
test ( 'Base route' , ( ) => {
11
11
const accurateResult = execPath ( '/' , '/' ) ;
12
- assert . equal ( accurateResult , { path : '/' , params : { } , query : { } } ) ;
12
+ assert . equal ( accurateResult , { path : '/' , pathParams : { } , searchParams : { } } ) ;
13
13
14
14
const inaccurateResult = execPath ( '/user/1' , '/' ) ;
15
15
assert . equal ( inaccurateResult , undefined ) ;
16
16
} ) ;
17
17
18
18
test ( 'Param route' , ( ) => {
19
19
const accurateResult = execPath ( '/user/2' , '/user/:id' ) ;
20
- assert . equal ( accurateResult , { path : '/user/2' , params : { id : '2' } , id : '2' , query : { } } ) ;
20
+ assert . equal ( accurateResult , { path : '/user/2' , pathParams : { id : '2' } , id : '2' , searchParams : { } } ) ;
21
21
22
22
const inaccurateResult = execPath ( '/' , '/user/:id' ) ;
23
23
assert . equal ( inaccurateResult , undefined ) ;
24
24
} ) ;
25
25
26
26
test ( 'Param rest segment' , ( ) => {
27
27
const accurateResult = execPath ( '/user/foo' , '/user/*' ) ;
28
- assert . equal ( accurateResult , { path : '/user/foo' , params : { } , query : { } , rest : '/foo' } ) ;
28
+ assert . equal ( accurateResult , { path : '/user/foo' , pathParams : { } , searchParams : { } , rest : '/foo' } ) ;
29
29
30
30
const accurateResult2 = execPath ( '/user/foo/bar/baz' , '/user/*' ) ;
31
- assert . equal ( accurateResult2 , { path : '/user/foo/bar/baz' , params : { } , query : { } , rest : '/foo/bar/baz' } ) ;
31
+ assert . equal ( accurateResult2 , { path : '/user/foo/bar/baz' , pathParams : { } , searchParams : { } , rest : '/foo/bar/baz' } ) ;
32
32
33
33
const inaccurateResult = execPath ( '/user' , '/user/*' ) ;
34
34
assert . equal ( inaccurateResult , undefined ) ;
35
35
} ) ;
36
36
37
37
test ( 'Param route with rest segment' , ( ) => {
38
38
const accurateResult = execPath ( '/user/2/foo' , '/user/:id/*' ) ;
39
- assert . equal ( accurateResult , { path : '/user/2/foo' , params : { id : '2' } , id : '2' , query : { } , rest : '/foo' } ) ;
39
+ assert . equal ( accurateResult , { path : '/user/2/foo' , pathParams : { id : '2' } , id : '2' , searchParams : { } , rest : '/foo' } ) ;
40
40
41
41
const accurateResult2 = execPath ( '/user/2/foo/bar/bob' , '/user/:id/*' ) ;
42
42
assert . equal ( accurateResult2 , {
43
43
path : '/user/2/foo/bar/bob' ,
44
- params : { id : '2' } ,
44
+ pathParams : { id : '2' } ,
45
45
id : '2' ,
46
- query : { } ,
46
+ searchParams : { } ,
47
47
rest : '/foo/bar/bob'
48
48
} ) ;
49
49
@@ -53,30 +53,30 @@ test('Param route with rest segment', () => {
53
53
54
54
test ( 'Optional param route' , ( ) => {
55
55
const accurateResult = execPath ( '/user' , '/user/:id?' ) ;
56
- assert . equal ( accurateResult , { path : '/user' , params : { id : undefined } , id : undefined , query : { } } ) ;
56
+ assert . equal ( accurateResult , { path : '/user' , pathParams : { id : undefined } , id : undefined , searchParams : { } } ) ;
57
57
58
58
const inaccurateResult = execPath ( '/' , '/user/:id?' ) ;
59
59
assert . equal ( inaccurateResult , undefined ) ;
60
60
} ) ;
61
61
62
62
test ( 'Optional rest param route "/:x*"' , ( ) => {
63
63
const matchedResult = execPath ( '/user' , '/user/:id*' ) ;
64
- assert . equal ( matchedResult , { path : '/user' , params : { id : undefined } , id : undefined , query : { } } ) ;
64
+ assert . equal ( matchedResult , { path : '/user' , pathParams : { id : undefined } , id : undefined , searchParams : { } } ) ;
65
65
66
66
const matchedResultWithSlash = execPath ( '/user/foo/bar' , '/user/:id*' ) ;
67
67
assert . equal ( matchedResultWithSlash , {
68
68
path : '/user/foo/bar' ,
69
- params : { id : 'foo/bar' } ,
69
+ pathParams : { id : 'foo/bar' } ,
70
70
id : 'foo/bar' ,
71
- query : { }
71
+ searchParams : { }
72
72
} ) ;
73
73
74
74
const emptyResult = execPath ( '/user' , '/user/:id*' ) ;
75
75
assert . equal ( emptyResult , {
76
76
path : '/user' ,
77
- params : { id : undefined } ,
77
+ pathParams : { id : undefined } ,
78
78
id : undefined ,
79
- query : { }
79
+ searchParams : { }
80
80
} ) ;
81
81
82
82
const inaccurateResult = execPath ( '/' , '/user/:id*' ) ;
@@ -85,14 +85,14 @@ test('Optional rest param route "/:x*"', () => {
85
85
86
86
test ( 'Rest param route "/:x+"' , ( ) => {
87
87
const matchedResult = execPath ( '/user/foo' , '/user/:id+' ) ;
88
- assert . equal ( matchedResult , { path : '/user/foo' , params : { id : 'foo' } , id : 'foo' , query : { } } ) ;
88
+ assert . equal ( matchedResult , { path : '/user/foo' , pathParams : { id : 'foo' } , id : 'foo' , searchParams : { } } ) ;
89
89
90
90
const matchedResultWithSlash = execPath ( '/user/foo/bar' , '/user/:id+' ) ;
91
91
assert . equal ( matchedResultWithSlash , {
92
92
path : '/user/foo/bar' ,
93
- params : { id : 'foo/bar' } ,
93
+ pathParams : { id : 'foo/bar' } ,
94
94
id : 'foo/bar' ,
95
- query : { }
95
+ searchParams : { }
96
96
} ) ;
97
97
98
98
const emptyResult = execPath ( '/user' , '/user/:id+' ) ;
@@ -106,22 +106,22 @@ test('Handles leading/trailing slashes', () => {
106
106
const result = execPath ( '/about-late/_SEGMENT1_/_SEGMENT2_/' , '/about-late/:seg1/:seg2/' ) ;
107
107
assert . equal ( result , {
108
108
path : '/about-late/_SEGMENT1_/_SEGMENT2_/' ,
109
- params : {
109
+ pathParams : {
110
110
seg1 : '_SEGMENT1_' ,
111
111
seg2 : '_SEGMENT2_'
112
112
} ,
113
113
seg1 : '_SEGMENT1_' ,
114
114
seg2 : '_SEGMENT2_' ,
115
- query : { }
115
+ searchParams : { }
116
116
} ) ;
117
117
} ) ;
118
118
119
119
test ( 'should not overwrite existing properties' , ( ) => {
120
- const result = execPath ( '/foo/bar' , '/:path/:query ' , { path : '/custom-path' } ) ;
120
+ const result = execPath ( '/foo/bar' , '/:path/:searchParams ' , { path : '/custom-path' } ) ;
121
121
assert . equal ( result , {
122
- params : { path : 'foo' , query : 'bar' } ,
122
+ pathParams : { path : 'foo' , searchParams : 'bar' } ,
123
123
path : '/custom-path' ,
124
- query : { }
124
+ searchParams : { } ,
125
125
} ) ;
126
126
} ) ;
127
127
0 commit comments