-
-
Notifications
You must be signed in to change notification settings - Fork 884
Expand file tree
/
Copy pathvercel-overrides.test.ts
More file actions
68 lines (62 loc) · 2.62 KB
/
Copy pathvercel-overrides.test.ts
File metadata and controls
68 lines (62 loc) · 2.62 KB
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
import { describe, expect, it } from "vitest";
import { getPrerenderOverrides } from "../../src/presets/vercel/utils.ts";
describe("getPrerenderOverrides", () => {
it("returns no overrides without prerendered routes", () => {
expect(getPrerenderOverrides()).toEqual({});
expect(getPrerenderOverrides([])).toEqual({});
});
it("skips files Vercel serves as directory indexes", () => {
expect(
getPrerenderOverrides([
{ route: "/", fileName: "/index.html" },
{ route: "/noslash", fileName: "/noslash/index.html" },
{ route: "/nested/deep/", fileName: "/nested/deep/index.html" },
// Extensionless index, e.g. a non-HTML route with a trailing slash
{ route: "/api/data/", fileName: "/api/data/index" },
])
).toEqual({});
});
// Keeping the trailing slash makes the path unmatchable (#4392)
it("does not emit a trailing-slash path", () => {
expect(getPrerenderOverrides([{ route: "/slash/", fileName: "/slash/index.html" }])).toEqual(
{}
);
expect(getPrerenderOverrides([{ route: "/slash/", fileName: "/renamed/index.html" }])).toEqual({
"renamed/index.html": { path: "slash" },
});
});
it("overrides files that are not served at their route", () => {
expect(
getPrerenderOverrides([
// `autoSubfolderIndex: false`
{ route: "/about", fileName: "/about.html" },
{ route: "/blog/post", fileName: "/blog/post.html" },
// `fileName` rewritten in a `prerender:generate` hook
{ route: "/bar/", fileName: "/renamed/index.html" },
])
).toEqual({
"about.html": { path: "about" },
"blog/post.html": { path: "blog/post" },
"renamed/index.html": { path: "bar" },
});
});
// Vercel deletes the original entry when re-keying, so an override pointing a
// file at its own path would remove it from the deployment entirely
it("never points a file at its own path", () => {
const overrides = getPrerenderOverrides([
{ route: "/foo.html", fileName: "/foo.html" },
{ route: "/foo/index.html", fileName: "/foo/index.html" },
{ route: "/data.json", fileName: "/data.json" },
// Route and file name normalize to the same key despite different spelling
{ route: "/self/", fileName: "/self" },
{ route: "/about", fileName: "/about.html" },
]);
for (const [file, { path }] of Object.entries(overrides)) {
expect(path).not.toBe(file);
}
expect(overrides).toEqual({ "about.html": { path: "about" } });
});
it("ignores routes without a fileName", () => {
expect(getPrerenderOverrides([{ route: "/skipped" }])).toEqual({});
});
});