forked from remix-run/remix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routesConvention-test.ts
88 lines (85 loc) · 3.44 KB
/
routesConvention-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
import { createRoutePath } from "../config/routesConvention";
describe("createRoutePath", () => {
describe("creates proper route paths", () => {
let tests: [string, string | undefined][] = [
["routes/$", "routes/*"],
["routes/sub/$", "routes/sub/*"],
["routes.sub/$", "routes/sub/*"],
["routes/$slug", "routes/:slug"],
["routes/sub/$slug", "routes/sub/:slug"],
["routes.sub/$slug", "routes/sub/:slug"],
["$", "*"],
["nested/$", "nested/*"],
["flat.$", "flat/*"],
["$slug", ":slug"],
["nested/$slug", "nested/:slug"],
["flat.$slug", "flat/:slug"],
["flat.sub", "flat/sub"],
["nested/index", "nested"],
["flat.index", "flat"],
["index", undefined],
["__layout/index", undefined],
["__layout/test", "test"],
["__layout.test", "test"],
["__layout/$slug", ":slug"],
["nested/__layout/$slug", "nested/:slug"],
["$slug[.]json", ":slug.json"],
["sub/[sitemap.xml]", "sub/sitemap.xml"],
["posts/$slug/[image.jpg]", "posts/:slug/image.jpg"],
["$[$dollabills].[.]lol[/]what/[$].$", ":$dollabills/.lol/what/$/*"],
["sub.[[]", "sub/["],
["sub.]", "sub/]"],
["sub.[[]]", "sub/[]"],
["sub.[[]", "sub/["],
["beef]", "beef]"],
["[index]", "index"],
["test/inde[x]", "test/index"],
["[i]ndex/[[].[[]]", "index/[/[]"],
// Optional segment routes
["(routes)/$", "routes?/*"],
["(routes)/($)", "routes?/*?"], // TODO: Fails, do we want to allow this?
["(routes)/(sub)/$", "routes?/sub?/*"],
["(routes).(sub)/$", "routes?/sub?/*"],
["(routes.sub)/$", "routes?/sub?/*"], // TODO: Fails, do we want to allow this?
["(routes)/($slug)", "routes?/:slug?"],
["(routes)/sub/($slug)", "routes?/sub/:slug?"],
["(routes).sub/($slug)", "routes?/sub/:slug?"],
["($)", "*?"], // TODO: Fails, do we want to allow this?
["(nested)/$", "nested?/*"],
["(flat).$", "flat?/*"],
["($slug)", ":slug?"],
["(nested)/($slug)", "nested?/:slug?"],
["(flat).($slug)", "flat?/:slug?"],
["flat.(sub)", "flat/sub?"],
["(nested)/(index)", "nested?"], // Fails with `"flat?/index?"`
["(flat).(index)", "flat?"], // Fails with `"flat?/index?"`
["(index)", undefined], // Fails with `"index?"`"
["(__layout)/(index)", undefined], // Fails with __layout?/index?
["__layout/(test)", "test?"],
["__layout.(test)", "test?"],
["__layout/($slug)", ":slug?"],
["(nested)/__layout/($slug)", "nested?/:slug?"],
["($slug[.]json)", ":slug.json?"],
["(sub)/([sitemap.xml])", "sub?/sitemap.xml?"],
["(sub)/[(sitemap.xml)]", "sub?/sitemap.xml?"], // TODO should this have been sub?/(sitemap.xml)
["(posts)/($slug)/([image.jpg])", "posts?/:slug?/image.jpg?"],
[
"($[$dollabills]).([.]lol)[/](what)/([$]).($)", // TODO outputs ":$dollabills?/.lol?/what?/$?/:?"
":$dollabills/.lol/what/$/*",
],
["(sub).([[])", "sub?/[?"],
["(sub).(])", "sub?/)?"],
["(sub).([([])])", "sub/[]"], // Fails with "sub?/([)]?"
["(sub).([[])", "sub?/[?"],
["(beef])", "beef]?"],
["([index])", "index?"],
["(test)/(inde[x])", "test?/index?"],
["([i]ndex)/([[]).([[]])", "index?/[?/[]?"],
];
for (let [input, expected] of tests) {
it(`"${input}" -> "${expected}"`, () => {
expect(createRoutePath(input)).toBe(expected);
});
}
});
});