forked from remix-run/remix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
defineRoutes-test.ts
100 lines (94 loc) · 2.92 KB
/
defineRoutes-test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { defineRoutes } from "../config/routes";
describe("defineRoutes", () => {
it("returns an array of routes", () => {
let routes = defineRoutes((route) => {
route("/", "routes/home.js");
route("inbox", "routes/inbox.js", () => {
route("/", "routes/inbox/index.js", { index: true });
route(":messageId", "routes/inbox/$messageId.js");
route("archive", "routes/inbox/archive.js");
});
});
expect(routes).toMatchInlineSnapshot(`
Object {
"routes/home": Object {
"caseSensitive": undefined,
"file": "routes/home.js",
"id": "routes/home",
"index": undefined,
"parentId": undefined,
"path": "/",
},
"routes/inbox": Object {
"caseSensitive": undefined,
"file": "routes/inbox.js",
"id": "routes/inbox",
"index": undefined,
"parentId": undefined,
"path": "inbox",
},
"routes/inbox/$messageId": Object {
"caseSensitive": undefined,
"file": "routes/inbox/$messageId.js",
"id": "routes/inbox/$messageId",
"index": undefined,
"parentId": "routes/inbox",
"path": ":messageId",
},
"routes/inbox/archive": Object {
"caseSensitive": undefined,
"file": "routes/inbox/archive.js",
"id": "routes/inbox/archive",
"index": undefined,
"parentId": "routes/inbox",
"path": "archive",
},
"routes/inbox/index": Object {
"caseSensitive": undefined,
"file": "routes/inbox/index.js",
"id": "routes/inbox/index",
"index": true,
"parentId": "routes/inbox",
"path": "/",
},
}
`);
});
it("works with async data", async () => {
// Read everything *before* calling defineRoutes.
let fakeDirectory = await Promise.resolve(["one.md", "two.md"]);
let routes = defineRoutes((route) => {
for (let file of fakeDirectory) {
route(file.replace(/\.md$/, ""), file);
}
});
expect(routes).toMatchInlineSnapshot(`
Object {
"one": Object {
"caseSensitive": undefined,
"file": "one.md",
"id": "one",
"index": undefined,
"parentId": undefined,
"path": "one",
},
"two": Object {
"caseSensitive": undefined,
"file": "two.md",
"id": "two",
"index": undefined,
"parentId": undefined,
"path": "two",
},
}
`);
});
it("allows multiple routes with the same route module", () => {
let routes = defineRoutes((route) => {
route("/user/:id", "routes/index.tsx", { id: "user-by-id" });
route("/user", "routes/index.tsx", { id: "user" });
route("/other", "routes/other-route.tsx");
});
expect(Object.entries(routes)).toHaveLength(3);
});
});