@esmx/router 3.0.0-rc.29 → 3.0.0-rc.30

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.
Files changed (59) hide show
  1. package/README.zh-CN.md +82 -1
  2. package/dist/index.d.ts +1 -2
  3. package/dist/index.mjs +0 -1
  4. package/package.json +3 -3
  5. package/src/index.ts +0 -3
  6. package/dist/index.test.d.ts +0 -1
  7. package/dist/index.test.mjs +0 -8
  8. package/dist/location.test.d.ts +0 -8
  9. package/dist/location.test.mjs +0 -370
  10. package/dist/matcher.test.d.ts +0 -1
  11. package/dist/matcher.test.mjs +0 -1492
  12. package/dist/micro-app.dom.test.d.ts +0 -1
  13. package/dist/micro-app.dom.test.mjs +0 -532
  14. package/dist/navigation.test.d.ts +0 -1
  15. package/dist/navigation.test.mjs +0 -681
  16. package/dist/route-task.test.d.ts +0 -1
  17. package/dist/route-task.test.mjs +0 -673
  18. package/dist/route-transition.test.d.ts +0 -1
  19. package/dist/route-transition.test.mjs +0 -146
  20. package/dist/route.test.d.ts +0 -1
  21. package/dist/route.test.mjs +0 -1664
  22. package/dist/router-back.test.d.ts +0 -1
  23. package/dist/router-back.test.mjs +0 -361
  24. package/dist/router-forward.test.d.ts +0 -1
  25. package/dist/router-forward.test.mjs +0 -376
  26. package/dist/router-go.test.d.ts +0 -1
  27. package/dist/router-go.test.mjs +0 -73
  28. package/dist/router-guards-cleanup.test.d.ts +0 -1
  29. package/dist/router-guards-cleanup.test.mjs +0 -437
  30. package/dist/router-push.test.d.ts +0 -1
  31. package/dist/router-push.test.mjs +0 -115
  32. package/dist/router-replace.test.d.ts +0 -1
  33. package/dist/router-replace.test.mjs +0 -114
  34. package/dist/router-resolve.test.d.ts +0 -1
  35. package/dist/router-resolve.test.mjs +0 -393
  36. package/dist/router-restart-app.dom.test.d.ts +0 -1
  37. package/dist/router-restart-app.dom.test.mjs +0 -616
  38. package/dist/router-window-navigation.test.d.ts +0 -1
  39. package/dist/router-window-navigation.test.mjs +0 -359
  40. package/dist/util.test.d.ts +0 -1
  41. package/dist/util.test.mjs +0 -1020
  42. package/src/index.test.ts +0 -9
  43. package/src/location.test.ts +0 -406
  44. package/src/matcher.test.ts +0 -1685
  45. package/src/micro-app.dom.test.ts +0 -708
  46. package/src/navigation.test.ts +0 -858
  47. package/src/route-task.test.ts +0 -901
  48. package/src/route-transition.test.ts +0 -178
  49. package/src/route.test.ts +0 -2014
  50. package/src/router-back.test.ts +0 -487
  51. package/src/router-forward.test.ts +0 -506
  52. package/src/router-go.test.ts +0 -91
  53. package/src/router-guards-cleanup.test.ts +0 -595
  54. package/src/router-push.test.ts +0 -140
  55. package/src/router-replace.test.ts +0 -139
  56. package/src/router-resolve.test.ts +0 -475
  57. package/src/router-restart-app.dom.test.ts +0 -783
  58. package/src/router-window-navigation.test.ts +0 -457
  59. package/src/util.test.ts +0 -1262
@@ -1,178 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, it, test } from 'vitest';
2
- import type { Route } from './route';
3
- import { Router } from './router';
4
- import { RouteType, RouterMode } from './types';
5
-
6
- describe('Route Transition Tests', () => {
7
- let router: Router;
8
-
9
- beforeEach(async () => {
10
- router = new Router({
11
- mode: RouterMode.memory,
12
- base: new URL('http://localhost:3000/'),
13
- routes: [
14
- { path: '/', component: () => 'Home' },
15
- { path: '/user/:id', component: () => 'User' },
16
- { path: '/about', component: () => 'About' },
17
- {
18
- path: '/async',
19
- asyncComponent: () => Promise.resolve('Async')
20
- }
21
- ]
22
- });
23
-
24
- await router.replace('/');
25
- });
26
-
27
- afterEach(() => {
28
- router.destroy();
29
- });
30
-
31
- describe('Basic transitions', () => {
32
- test('should successfully transition to new route', async () => {
33
- const route = await router.push('/user/123');
34
-
35
- expect(route.path).toBe('/user/123');
36
- expect(route.params.id).toBe('123');
37
- expect(route.handle).not.toBe(null);
38
- });
39
-
40
- test('should handle async component loading', async () => {
41
- const route = await router.push('/async');
42
-
43
- expect(route.path).toBe('/async');
44
- expect(route.handle).not.toBe(null);
45
- });
46
- });
47
-
48
- describe('Error handling', () => {
49
- test('should handle non-existent routes', async () => {
50
- const route = await router.push('/non-existent');
51
- expect(route.matched).toHaveLength(0);
52
- expect(route.config).toBe(null);
53
- });
54
-
55
- test('should handle component loading errors', async () => {
56
- const errorRouter = new Router({
57
- mode: RouterMode.memory,
58
- base: new URL('http://localhost:3000/'),
59
- routes: [
60
- { path: '/', component: () => 'Home' },
61
- {
62
- path: '/error',
63
- asyncComponent: () =>
64
- Promise.reject(new Error('Loading failed'))
65
- }
66
- ]
67
- });
68
-
69
- await errorRouter.replace('/');
70
- await expect(errorRouter.push('/error')).rejects.toThrow();
71
-
72
- errorRouter.destroy();
73
- });
74
- });
75
-
76
- describe('Concurrent navigation', () => {
77
- test('should handle concurrent navigation attempts', async () => {
78
- const promises = Array.from({ length: 5 }, (_, i) =>
79
- router.push(`/user/${i + 1}`).catch((err) => err)
80
- );
81
-
82
- const results = await Promise.all(promises);
83
-
84
- const successResults = results.filter((r) => !(r instanceof Error));
85
- const abortedResults = results.filter((r) => r instanceof Error);
86
-
87
- expect(successResults).toHaveLength(1);
88
- expect(abortedResults).toHaveLength(4);
89
-
90
- const successResult = successResults[0] as Route;
91
- expect(router.route.path).toBe(successResult.path);
92
- expect(router.route.params.id).toBe(successResult.params.id);
93
- });
94
- });
95
-
96
- describe('Route guards', () => {
97
- let guardRouter: Router;
98
- let guardLog: string[];
99
-
100
- beforeEach(async () => {
101
- guardLog = [];
102
-
103
- guardRouter = new Router({
104
- mode: RouterMode.memory,
105
- base: new URL('http://localhost:3000/'),
106
- routes: [
107
- { path: '/', component: () => 'Home' },
108
- {
109
- path: '/protected',
110
- component: () => 'Protected',
111
- beforeEnter: () => {
112
- guardLog.push('beforeEnter-protected');
113
- return false;
114
- }
115
- },
116
- {
117
- path: '/allowed',
118
- component: () => 'Allowed',
119
- beforeEnter: () => {
120
- guardLog.push('beforeEnter-allowed');
121
- }
122
- }
123
- ]
124
- });
125
-
126
- await guardRouter.replace('/');
127
- });
128
-
129
- afterEach(() => {
130
- guardRouter.destroy();
131
- });
132
-
133
- test('should block navigation when guard returns false', async () => {
134
- await expect(guardRouter.push('/protected')).rejects.toThrow();
135
- expect(guardLog).toContain('beforeEnter-protected');
136
- expect(guardRouter.route.path).toBe('/');
137
- });
138
-
139
- test('should allow navigation when guard returns true', async () => {
140
- const route = await guardRouter.push('/allowed');
141
-
142
- expect(guardLog).toContain('beforeEnter-allowed');
143
- expect(route.path).toBe('/allowed');
144
- expect(guardRouter.route.path).toBe('/allowed');
145
- });
146
- });
147
-
148
- describe('Navigation types', () => {
149
- test('should correctly set route type for push navigation', async () => {
150
- const route = await router.push('/user/123');
151
- expect(route.type).toBe(RouteType.push);
152
- });
153
-
154
- test('should correctly set route type for replace navigation', async () => {
155
- const route = await router.replace('/user/123');
156
- expect(route.type).toBe(RouteType.replace);
157
- });
158
- });
159
-
160
- describe('Route parameters and query', () => {
161
- test('should correctly extract route parameters', async () => {
162
- const route = await router.push('/user/456');
163
-
164
- expect(route.params.id).toBe('456');
165
- expect(route.path).toBe('/user/456');
166
- });
167
-
168
- test('should handle query parameters', async () => {
169
- const route = await router.push(
170
- '/user/123?tab=profile&active=true'
171
- );
172
-
173
- expect(route.params.id).toBe('123');
174
- expect(route.query.tab).toBe('profile');
175
- expect(route.query.active).toBe('true');
176
- });
177
- });
178
- });