@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
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
|
2
|
-
import { Router } from "./router.mjs";
|
|
3
|
-
import { RouteType, RouterMode } from "./types.mjs";
|
|
4
|
-
describe("Route Transition Tests", () => {
|
|
5
|
-
let router;
|
|
6
|
-
beforeEach(async () => {
|
|
7
|
-
router = new Router({
|
|
8
|
-
mode: RouterMode.memory,
|
|
9
|
-
base: new URL("http://localhost:3000/"),
|
|
10
|
-
routes: [
|
|
11
|
-
{ path: "/", component: () => "Home" },
|
|
12
|
-
{ path: "/user/:id", component: () => "User" },
|
|
13
|
-
{ path: "/about", component: () => "About" },
|
|
14
|
-
{
|
|
15
|
-
path: "/async",
|
|
16
|
-
asyncComponent: () => Promise.resolve("Async")
|
|
17
|
-
}
|
|
18
|
-
]
|
|
19
|
-
});
|
|
20
|
-
await router.replace("/");
|
|
21
|
-
});
|
|
22
|
-
afterEach(() => {
|
|
23
|
-
router.destroy();
|
|
24
|
-
});
|
|
25
|
-
describe("Basic transitions", () => {
|
|
26
|
-
test("should successfully transition to new route", async () => {
|
|
27
|
-
const route = await router.push("/user/123");
|
|
28
|
-
expect(route.path).toBe("/user/123");
|
|
29
|
-
expect(route.params.id).toBe("123");
|
|
30
|
-
expect(route.handle).not.toBe(null);
|
|
31
|
-
});
|
|
32
|
-
test("should handle async component loading", async () => {
|
|
33
|
-
const route = await router.push("/async");
|
|
34
|
-
expect(route.path).toBe("/async");
|
|
35
|
-
expect(route.handle).not.toBe(null);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
describe("Error handling", () => {
|
|
39
|
-
test("should handle non-existent routes", async () => {
|
|
40
|
-
const route = await router.push("/non-existent");
|
|
41
|
-
expect(route.matched).toHaveLength(0);
|
|
42
|
-
expect(route.config).toBe(null);
|
|
43
|
-
});
|
|
44
|
-
test("should handle component loading errors", async () => {
|
|
45
|
-
const errorRouter = new Router({
|
|
46
|
-
mode: RouterMode.memory,
|
|
47
|
-
base: new URL("http://localhost:3000/"),
|
|
48
|
-
routes: [
|
|
49
|
-
{ path: "/", component: () => "Home" },
|
|
50
|
-
{
|
|
51
|
-
path: "/error",
|
|
52
|
-
asyncComponent: () => Promise.reject(new Error("Loading failed"))
|
|
53
|
-
}
|
|
54
|
-
]
|
|
55
|
-
});
|
|
56
|
-
await errorRouter.replace("/");
|
|
57
|
-
await expect(errorRouter.push("/error")).rejects.toThrow();
|
|
58
|
-
errorRouter.destroy();
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
describe("Concurrent navigation", () => {
|
|
62
|
-
test("should handle concurrent navigation attempts", async () => {
|
|
63
|
-
const promises = Array.from(
|
|
64
|
-
{ length: 5 },
|
|
65
|
-
(_, i) => router.push("/user/".concat(i + 1)).catch((err) => err)
|
|
66
|
-
);
|
|
67
|
-
const results = await Promise.all(promises);
|
|
68
|
-
const successResults = results.filter((r) => !(r instanceof Error));
|
|
69
|
-
const abortedResults = results.filter((r) => r instanceof Error);
|
|
70
|
-
expect(successResults).toHaveLength(1);
|
|
71
|
-
expect(abortedResults).toHaveLength(4);
|
|
72
|
-
const successResult = successResults[0];
|
|
73
|
-
expect(router.route.path).toBe(successResult.path);
|
|
74
|
-
expect(router.route.params.id).toBe(successResult.params.id);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
describe("Route guards", () => {
|
|
78
|
-
let guardRouter;
|
|
79
|
-
let guardLog;
|
|
80
|
-
beforeEach(async () => {
|
|
81
|
-
guardLog = [];
|
|
82
|
-
guardRouter = new Router({
|
|
83
|
-
mode: RouterMode.memory,
|
|
84
|
-
base: new URL("http://localhost:3000/"),
|
|
85
|
-
routes: [
|
|
86
|
-
{ path: "/", component: () => "Home" },
|
|
87
|
-
{
|
|
88
|
-
path: "/protected",
|
|
89
|
-
component: () => "Protected",
|
|
90
|
-
beforeEnter: () => {
|
|
91
|
-
guardLog.push("beforeEnter-protected");
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
path: "/allowed",
|
|
97
|
-
component: () => "Allowed",
|
|
98
|
-
beforeEnter: () => {
|
|
99
|
-
guardLog.push("beforeEnter-allowed");
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
]
|
|
103
|
-
});
|
|
104
|
-
await guardRouter.replace("/");
|
|
105
|
-
});
|
|
106
|
-
afterEach(() => {
|
|
107
|
-
guardRouter.destroy();
|
|
108
|
-
});
|
|
109
|
-
test("should block navigation when guard returns false", async () => {
|
|
110
|
-
await expect(guardRouter.push("/protected")).rejects.toThrow();
|
|
111
|
-
expect(guardLog).toContain("beforeEnter-protected");
|
|
112
|
-
expect(guardRouter.route.path).toBe("/");
|
|
113
|
-
});
|
|
114
|
-
test("should allow navigation when guard returns true", async () => {
|
|
115
|
-
const route = await guardRouter.push("/allowed");
|
|
116
|
-
expect(guardLog).toContain("beforeEnter-allowed");
|
|
117
|
-
expect(route.path).toBe("/allowed");
|
|
118
|
-
expect(guardRouter.route.path).toBe("/allowed");
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
describe("Navigation types", () => {
|
|
122
|
-
test("should correctly set route type for push navigation", async () => {
|
|
123
|
-
const route = await router.push("/user/123");
|
|
124
|
-
expect(route.type).toBe(RouteType.push);
|
|
125
|
-
});
|
|
126
|
-
test("should correctly set route type for replace navigation", async () => {
|
|
127
|
-
const route = await router.replace("/user/123");
|
|
128
|
-
expect(route.type).toBe(RouteType.replace);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
describe("Route parameters and query", () => {
|
|
132
|
-
test("should correctly extract route parameters", async () => {
|
|
133
|
-
const route = await router.push("/user/456");
|
|
134
|
-
expect(route.params.id).toBe("456");
|
|
135
|
-
expect(route.path).toBe("/user/456");
|
|
136
|
-
});
|
|
137
|
-
test("should handle query parameters", async () => {
|
|
138
|
-
const route = await router.push(
|
|
139
|
-
"/user/123?tab=profile&active=true"
|
|
140
|
-
);
|
|
141
|
-
expect(route.params.id).toBe("123");
|
|
142
|
-
expect(route.query.tab).toBe("profile");
|
|
143
|
-
expect(route.query.active).toBe("true");
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
});
|
package/dist/route.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|