@esmx/router 3.0.0-rc.29 → 3.0.0-rc.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.zh-CN.md +82 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.mjs +0 -1
- package/dist/navigation.mjs +4 -4
- package/package.json +3 -3
- package/src/index.ts +0 -3
- package/src/navigation.ts +4 -4
- package/dist/index.test.d.ts +0 -1
- package/dist/index.test.mjs +0 -8
- package/dist/location.test.d.ts +0 -8
- package/dist/location.test.mjs +0 -370
- package/dist/matcher.test.d.ts +0 -1
- package/dist/matcher.test.mjs +0 -1492
- package/dist/micro-app.dom.test.d.ts +0 -1
- package/dist/micro-app.dom.test.mjs +0 -532
- package/dist/navigation.test.d.ts +0 -1
- package/dist/navigation.test.mjs +0 -681
- package/dist/route-task.test.d.ts +0 -1
- package/dist/route-task.test.mjs +0 -673
- package/dist/route-transition.test.d.ts +0 -1
- package/dist/route-transition.test.mjs +0 -146
- package/dist/route.test.d.ts +0 -1
- package/dist/route.test.mjs +0 -1664
- package/dist/router-back.test.d.ts +0 -1
- package/dist/router-back.test.mjs +0 -361
- package/dist/router-forward.test.d.ts +0 -1
- package/dist/router-forward.test.mjs +0 -376
- package/dist/router-go.test.d.ts +0 -1
- package/dist/router-go.test.mjs +0 -73
- package/dist/router-guards-cleanup.test.d.ts +0 -1
- package/dist/router-guards-cleanup.test.mjs +0 -437
- package/dist/router-push.test.d.ts +0 -1
- package/dist/router-push.test.mjs +0 -115
- package/dist/router-replace.test.d.ts +0 -1
- package/dist/router-replace.test.mjs +0 -114
- package/dist/router-resolve.test.d.ts +0 -1
- package/dist/router-resolve.test.mjs +0 -393
- package/dist/router-restart-app.dom.test.d.ts +0 -1
- package/dist/router-restart-app.dom.test.mjs +0 -616
- package/dist/router-window-navigation.test.d.ts +0 -1
- package/dist/router-window-navigation.test.mjs +0 -359
- package/dist/util.test.d.ts +0 -1
- package/dist/util.test.mjs +0 -1020
- package/src/index.test.ts +0 -9
- package/src/location.test.ts +0 -406
- package/src/matcher.test.ts +0 -1685
- package/src/micro-app.dom.test.ts +0 -708
- package/src/navigation.test.ts +0 -858
- package/src/route-task.test.ts +0 -901
- package/src/route-transition.test.ts +0 -178
- package/src/route.test.ts +0 -2014
- package/src/router-back.test.ts +0 -487
- package/src/router-forward.test.ts +0 -506
- package/src/router-go.test.ts +0 -91
- package/src/router-guards-cleanup.test.ts +0 -595
- package/src/router-push.test.ts +0 -140
- package/src/router-replace.test.ts +0 -139
- package/src/router-resolve.test.ts +0 -475
- package/src/router-restart-app.dom.test.ts +0 -783
- package/src/router-window-navigation.test.ts +0 -457
- package/src/util.test.ts +0 -1262
package/src/router-push.test.ts
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, test } from 'vitest';
|
|
2
|
-
import { Router } from './router';
|
|
3
|
-
import { RouteType, RouterMode } from './types';
|
|
4
|
-
|
|
5
|
-
describe('Router Push Tests', () => {
|
|
6
|
-
let router: Router;
|
|
7
|
-
|
|
8
|
-
beforeEach(async () => {
|
|
9
|
-
router = new Router({
|
|
10
|
-
mode: RouterMode.memory,
|
|
11
|
-
base: new URL('http://localhost:3000/'),
|
|
12
|
-
routes: [
|
|
13
|
-
{ path: '/', component: () => 'Home' },
|
|
14
|
-
{ path: '/user/:id', component: () => 'User' },
|
|
15
|
-
{ path: '/about', component: () => 'About' },
|
|
16
|
-
{
|
|
17
|
-
path: '/async',
|
|
18
|
-
asyncComponent: () =>
|
|
19
|
-
new Promise((resolve) =>
|
|
20
|
-
setTimeout(() => resolve('AsyncComponent'), 10)
|
|
21
|
-
)
|
|
22
|
-
}
|
|
23
|
-
]
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
await router.replace('/');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
afterEach(() => {
|
|
30
|
-
router.destroy();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
describe('Basic push navigation', () => {
|
|
34
|
-
test('should successfully push to new route', async () => {
|
|
35
|
-
const route = await router.push('/user/123');
|
|
36
|
-
|
|
37
|
-
expect(route.path).toBe('/user/123');
|
|
38
|
-
expect(route.params.id).toBe('123');
|
|
39
|
-
expect(route.type).toBe(RouteType.push);
|
|
40
|
-
expect(route.handle).not.toBe(null);
|
|
41
|
-
expect(router.route.path).toBe('/user/123');
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test('should handle query parameters in push', async () => {
|
|
45
|
-
const route = await router.push(
|
|
46
|
-
'/user/123?tab=profile&active=true'
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
expect(route.params.id).toBe('123');
|
|
50
|
-
expect(route.query.tab).toBe('profile');
|
|
51
|
-
expect(route.query.active).toBe('true');
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('should handle async component loading', async () => {
|
|
55
|
-
const route = await router.push('/async');
|
|
56
|
-
|
|
57
|
-
expect(route.path).toBe('/async');
|
|
58
|
-
expect(route.handle).not.toBe(null);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
describe('Error handling', () => {
|
|
63
|
-
test('should throw error for async component loading failure', async () => {
|
|
64
|
-
const errorRouter = new Router({
|
|
65
|
-
mode: RouterMode.memory,
|
|
66
|
-
base: new URL('http://localhost:3000/'),
|
|
67
|
-
routes: [
|
|
68
|
-
{ path: '/', component: () => 'Home' },
|
|
69
|
-
{
|
|
70
|
-
path: '/error',
|
|
71
|
-
asyncComponent: () =>
|
|
72
|
-
Promise.reject(new Error('Loading failed'))
|
|
73
|
-
}
|
|
74
|
-
]
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
await errorRouter.replace('/');
|
|
78
|
-
await expect(errorRouter.push('/error')).rejects.toThrow();
|
|
79
|
-
|
|
80
|
-
errorRouter.destroy();
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
test('should throw error when guard prevents navigation', async () => {
|
|
84
|
-
const guardRouter = new Router({
|
|
85
|
-
mode: RouterMode.memory,
|
|
86
|
-
base: new URL('http://localhost:3000/'),
|
|
87
|
-
routes: [
|
|
88
|
-
{ path: '/', component: () => 'Home' },
|
|
89
|
-
{
|
|
90
|
-
path: '/protected',
|
|
91
|
-
component: () => 'Protected',
|
|
92
|
-
beforeEnter: () => false
|
|
93
|
-
}
|
|
94
|
-
]
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
await guardRouter.replace('/');
|
|
98
|
-
await expect(guardRouter.push('/protected')).rejects.toThrow();
|
|
99
|
-
|
|
100
|
-
guardRouter.destroy();
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
describe('Concurrent navigation', () => {
|
|
105
|
-
test('should handle concurrent push operations', async () => {
|
|
106
|
-
const promises = [
|
|
107
|
-
router.push('/user/1').catch((err) => err),
|
|
108
|
-
router.push('/user/2').catch((err) => err)
|
|
109
|
-
];
|
|
110
|
-
|
|
111
|
-
const [result1, result2] = await Promise.all(promises);
|
|
112
|
-
|
|
113
|
-
const successResults = [result1, result2].filter(
|
|
114
|
-
(r) => !(r instanceof Error)
|
|
115
|
-
);
|
|
116
|
-
const errorResults = [result1, result2].filter(
|
|
117
|
-
(r) => r instanceof Error
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
expect(successResults).toHaveLength(1);
|
|
121
|
-
expect(errorResults).toHaveLength(1);
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
describe('Edge cases', () => {
|
|
126
|
-
test('should handle push to current route', async () => {
|
|
127
|
-
await router.push('/about');
|
|
128
|
-
const route = await router.push('/about');
|
|
129
|
-
|
|
130
|
-
expect(route.path).toBe('/about');
|
|
131
|
-
expect(route.handle).not.toBe(null);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
test('should handle empty parameter', async () => {
|
|
135
|
-
const route = await router.push('');
|
|
136
|
-
expect(route).toBeDefined();
|
|
137
|
-
expect(typeof route.path).toBe('string');
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
});
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, test } from 'vitest';
|
|
2
|
-
import { Router } from './router';
|
|
3
|
-
import { RouteType, RouterMode } from './types';
|
|
4
|
-
|
|
5
|
-
describe('Router Replace Tests', () => {
|
|
6
|
-
let router: Router;
|
|
7
|
-
|
|
8
|
-
beforeEach(async () => {
|
|
9
|
-
router = new Router({
|
|
10
|
-
mode: RouterMode.memory,
|
|
11
|
-
base: new URL('http://localhost:3000/'),
|
|
12
|
-
routes: [
|
|
13
|
-
{ path: '/', component: () => 'Home' },
|
|
14
|
-
{ path: '/user/:id', component: () => 'User' },
|
|
15
|
-
{ path: '/about', component: () => 'About' },
|
|
16
|
-
{
|
|
17
|
-
path: '/async',
|
|
18
|
-
asyncComponent: () =>
|
|
19
|
-
new Promise((resolve) =>
|
|
20
|
-
setTimeout(() => resolve('AsyncComponent'), 10)
|
|
21
|
-
)
|
|
22
|
-
}
|
|
23
|
-
]
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
await router.replace('/');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
afterEach(() => {
|
|
30
|
-
router.destroy();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
describe('Basic replace navigation', () => {
|
|
34
|
-
test('should successfully replace current route', async () => {
|
|
35
|
-
await router.push('/about');
|
|
36
|
-
const route = await router.replace('/user/123');
|
|
37
|
-
|
|
38
|
-
expect(route.path).toBe('/user/123');
|
|
39
|
-
expect(route.params.id).toBe('123');
|
|
40
|
-
expect(route.type).toBe(RouteType.replace);
|
|
41
|
-
expect(route.handle).not.toBe(null);
|
|
42
|
-
expect(router.route.path).toBe('/user/123');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test('should handle query parameters in replace', async () => {
|
|
46
|
-
const route = await router.replace(
|
|
47
|
-
'/user/123?tab=profile&active=true'
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
expect(route.params.id).toBe('123');
|
|
51
|
-
expect(route.query.tab).toBe('profile');
|
|
52
|
-
expect(route.query.active).toBe('true');
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test('should handle async component loading', async () => {
|
|
56
|
-
const route = await router.replace('/async');
|
|
57
|
-
|
|
58
|
-
expect(route.path).toBe('/async');
|
|
59
|
-
expect(route.handle).not.toBe(null);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe('Error handling', () => {
|
|
64
|
-
test('should throw error for async component loading failure', async () => {
|
|
65
|
-
const errorRouter = new Router({
|
|
66
|
-
mode: RouterMode.memory,
|
|
67
|
-
base: new URL('http://localhost:3000/'),
|
|
68
|
-
routes: [
|
|
69
|
-
{ path: '/', component: () => 'Home' },
|
|
70
|
-
{
|
|
71
|
-
path: '/error',
|
|
72
|
-
asyncComponent: () =>
|
|
73
|
-
Promise.reject(new Error('Loading failed'))
|
|
74
|
-
}
|
|
75
|
-
]
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
await errorRouter.replace('/');
|
|
79
|
-
await expect(errorRouter.replace('/error')).rejects.toThrow();
|
|
80
|
-
|
|
81
|
-
errorRouter.destroy();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test('should throw error when guard prevents navigation', async () => {
|
|
85
|
-
const guardRouter = new Router({
|
|
86
|
-
mode: RouterMode.memory,
|
|
87
|
-
base: new URL('http://localhost:3000/'),
|
|
88
|
-
routes: [
|
|
89
|
-
{ path: '/', component: () => 'Home' },
|
|
90
|
-
{
|
|
91
|
-
path: '/protected',
|
|
92
|
-
component: () => 'Protected',
|
|
93
|
-
beforeEnter: () => false
|
|
94
|
-
}
|
|
95
|
-
]
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
await guardRouter.replace('/');
|
|
99
|
-
await expect(guardRouter.replace('/protected')).rejects.toThrow();
|
|
100
|
-
|
|
101
|
-
guardRouter.destroy();
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
describe('History management', () => {
|
|
106
|
-
test('should not create new history entry', async () => {
|
|
107
|
-
await router.push('/about');
|
|
108
|
-
await router.replace('/user/123');
|
|
109
|
-
|
|
110
|
-
const backRoute = await router.back();
|
|
111
|
-
expect(backRoute?.path).toBe('/');
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
test('should replace current entry in history', async () => {
|
|
115
|
-
await router.push('/about');
|
|
116
|
-
await router.push('/user/456');
|
|
117
|
-
await router.replace('/user/789');
|
|
118
|
-
|
|
119
|
-
const backRoute = await router.back();
|
|
120
|
-
expect(backRoute?.path).toBe('/about');
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
describe('Edge cases', () => {
|
|
125
|
-
test('should handle replace to current route', async () => {
|
|
126
|
-
await router.push('/about');
|
|
127
|
-
const route = await router.replace('/about');
|
|
128
|
-
|
|
129
|
-
expect(route.path).toBe('/about');
|
|
130
|
-
expect(route.handle).not.toBe(null);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
test('should handle empty parameter', async () => {
|
|
134
|
-
const route = await router.replace('');
|
|
135
|
-
expect(route).toBeDefined();
|
|
136
|
-
expect(typeof route.path).toBe('string');
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
});
|