-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Expand file tree
/
Copy pathvite-manifests-test.ts
More file actions
143 lines (125 loc) · 3.55 KB
/
Copy pathvite-manifests-test.ts
File metadata and controls
143 lines (125 loc) · 3.55 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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import fs from "node:fs";
import path from "node:path";
import { test, expect } from "@playwright/test";
import getPort from "get-port";
import dedent from "dedent";
import { createProject, build, viteConfig } from "./helpers/vite.js";
const js = String.raw;
function createRoute(path: string) {
return {
[`app/routes/${path}`]: js`
export default function Route() {
return <p>Path: ${path}</p>;
}
`,
};
}
const TEST_ROUTES = [
"_index.tsx",
"parent-route.tsx",
"parent-route.child-route.tsx",
];
const files = {
"app/root.tsx": js`
import { Links, Meta, Outlet, Scripts } from "react-router";
export default function Root() {
return (
<html lang="en">
<head>
<Meta />
<Links />
</head>
<body>
<Outlet />
<Scripts />
</body>
</html>
);
}
`,
...Object.assign({}, ...TEST_ROUTES.map(createRoute)),
};
test.describe(() => {
let cwd: string;
test.beforeAll(async () => {
cwd = await createProject({
"react-router.config.ts": dedent(js`
export default {
buildEnd: async ({ buildManifest }) => {
let fs = await import("node:fs");
await fs.promises.writeFile(
"build/test-manifest.json",
JSON.stringify(buildManifest, null, 2),
"utf-8",
);
},
}
`),
"vite.config.ts": dedent(js`
import { reactRouter } from "@react-router/dev/vite";
export default {
build: { manifest: true },
plugins: [reactRouter()],
}
`),
...files,
});
build({ cwd });
});
test("Vite / manifests enabled / Vite manifests", () => {
let viteManifestFilesClient = fs.readdirSync(
path.join(cwd, "build", "client", ".vite"),
);
expect(viteManifestFilesClient).toEqual(["manifest.json"]);
let viteManifestFilesServer = fs.readdirSync(
path.join(cwd, "build", "server", ".vite"),
);
expect(viteManifestFilesServer).toEqual(["manifest.json"]);
});
test("Vite / manifests enabled / React Router build manifest", async () => {
let manifestPath = path.join(cwd, "build", "test-manifest.json");
expect(JSON.parse(fs.readFileSync(manifestPath, "utf8"))).toEqual({
routes: {
root: {
file: "root.tsx",
id: "root",
path: "",
},
"routes/_index": {
file: "routes/_index.tsx",
id: "routes/_index",
index: true,
parentId: "root",
},
"routes/parent-route": {
file: "routes/parent-route.tsx",
id: "routes/parent-route",
parentId: "root",
path: "parent-route",
},
"routes/parent-route.child-route": {
file: "routes/parent-route.child-route.tsx",
id: "routes/parent-route.child-route",
parentId: "routes/parent-route",
path: "child-route",
},
},
});
});
});
test.describe(() => {
let cwd: string;
test.beforeAll(async () => {
cwd = await createProject({
"vite.config.ts": await viteConfig.basic({ port: await getPort() }),
...files,
});
build({ cwd });
});
test("Vite / manifest disabled / Vite manifests", () => {
let manifestDirClient = path.join(cwd, "build", "client", ".vite");
expect(fs.existsSync(manifestDirClient)).toBe(false);
let manifestDirServer = path.join(cwd, "build", "server", ".vite");
expect(fs.existsSync(manifestDirServer)).toBe(false);
});
});