@@ -5,49 +5,49 @@ const BASE_URL = new URL('https://www.esmx.dev');
5
5
6
6
describe ( 'joinPathname' , ( ) => {
7
7
test ( '基本路径拼接' , ( ) => {
8
- assert . equal ( joinPathname ( 'test' ) , 'test' ) ;
9
- assert . equal ( joinPathname ( '/test' ) , 'test' ) ;
10
- assert . equal ( joinPathname ( 'test/' ) , 'test' ) ;
11
- assert . equal ( joinPathname ( '/test/' ) , 'test' ) ;
8
+ assert . equal ( joinPathname ( 'test' ) , '/ test' ) ;
9
+ assert . equal ( joinPathname ( '/test' ) , '/ test' ) ;
10
+ assert . equal ( joinPathname ( 'test/' ) , '/ test' ) ;
11
+ assert . equal ( joinPathname ( '/test/' ) , '/ test' ) ;
12
12
} ) ;
13
13
14
14
test ( '带base的路径拼接' , ( ) => {
15
- assert . equal ( joinPathname ( 'test' , '/api' ) , 'api/test' ) ;
16
- assert . equal ( joinPathname ( '/test' , '/api' ) , 'api/test' ) ;
17
- assert . equal ( joinPathname ( 'test' , 'api' ) , 'api/test' ) ;
18
- assert . equal ( joinPathname ( '/test' , 'api' ) , 'api/test' ) ;
15
+ assert . equal ( joinPathname ( 'test' , '/api' ) , '/ api/test' ) ;
16
+ assert . equal ( joinPathname ( '/test' , '/api' ) , '/ api/test' ) ;
17
+ assert . equal ( joinPathname ( 'test' , 'api' ) , '/ api/test' ) ;
18
+ assert . equal ( joinPathname ( '/test' , 'api' ) , '/ api/test' ) ;
19
19
} ) ;
20
20
21
21
test ( '多层级路径拼接' , ( ) => {
22
- assert . equal ( joinPathname ( 'test/path' ) , 'test/path' ) ;
23
- assert . equal ( joinPathname ( '/test/path' ) , 'test/path' ) ;
24
- assert . equal ( joinPathname ( 'test/path/' ) , 'test/path' ) ;
25
- assert . equal ( joinPathname ( '/test/path/' ) , 'test/path' ) ;
22
+ assert . equal ( joinPathname ( 'test/path' ) , '/ test/path' ) ;
23
+ assert . equal ( joinPathname ( '/test/path' ) , '/ test/path' ) ;
24
+ assert . equal ( joinPathname ( 'test/path/' ) , '/ test/path' ) ;
25
+ assert . equal ( joinPathname ( '/test/path/' ) , '/ test/path' ) ;
26
26
} ) ;
27
27
28
28
test ( '带base的多层级路径拼接' , ( ) => {
29
- assert . equal ( joinPathname ( 'test/path' , '/api' ) , 'api/test/path' ) ;
30
- assert . equal ( joinPathname ( '/test/path' , '/api' ) , 'api/test/path' ) ;
31
- assert . equal ( joinPathname ( 'test/path' , 'api' ) , 'api/test/path' ) ;
32
- assert . equal ( joinPathname ( '/test/path' , 'api' ) , 'api/test/path' ) ;
29
+ assert . equal ( joinPathname ( 'test/path' , '/api' ) , '/ api/test/path' ) ;
30
+ assert . equal ( joinPathname ( '/test/path' , '/api' ) , '/ api/test/path' ) ;
31
+ assert . equal ( joinPathname ( 'test/path' , 'api' ) , '/ api/test/path' ) ;
32
+ assert . equal ( joinPathname ( '/test/path' , 'api' ) , '/ api/test/path' ) ;
33
33
} ) ;
34
34
35
35
test ( '处理重复斜杠' , ( ) => {
36
- assert . equal ( joinPathname ( '//test' ) , 'test' ) ;
37
- assert . equal ( joinPathname ( 'test//path' ) , 'test/path' ) ;
38
- assert . equal ( joinPathname ( '//test//path//' ) , 'test/path' ) ;
39
- assert . equal ( joinPathname ( 'test//path' , '/api//' ) , 'api/test/path' ) ;
36
+ assert . equal ( joinPathname ( '//test' ) , '/ test' ) ;
37
+ assert . equal ( joinPathname ( 'test//path' ) , '/ test/path' ) ;
38
+ assert . equal ( joinPathname ( '//test//path//' ) , '/ test/path' ) ;
39
+ assert . equal ( joinPathname ( 'test//path' , '/api//' ) , '/ api/test/path' ) ;
40
40
} ) ;
41
41
42
42
test ( '处理空值' , ( ) => {
43
- assert . equal ( joinPathname ( '' ) , '' ) ;
44
- assert . equal ( joinPathname ( '' , '' ) , '' ) ;
45
- assert . equal ( joinPathname ( 'test' , '' ) , 'test' ) ;
46
- assert . equal ( joinPathname ( '' , 'api' ) , 'api' ) ;
43
+ assert . equal ( joinPathname ( '' ) , '/ ' ) ;
44
+ assert . equal ( joinPathname ( '' , '' ) , '/ ' ) ;
45
+ assert . equal ( joinPathname ( 'test' , '' ) , '/ test' ) ;
46
+ assert . equal ( joinPathname ( '' , 'api' ) , '/ api' ) ;
47
47
} ) ;
48
48
} ) ;
49
49
50
- describe ( 'base ' , ( ) => {
50
+ describe ( 'createMatcher ' , ( ) => {
51
51
test ( '基本路由匹配' , ( ) => {
52
52
const matcher = createMatcher ( [
53
53
{
0 commit comments