-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathvite-route-added-test.ts
76 lines (65 loc) · 2.06 KB
/
vite-route-added-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
import fs from "node:fs/promises";
import path from "node:path";
import { test, expect } from "@playwright/test";
import getPort from "get-port";
import { createProject, dev, viteConfig } from "./helpers/vite.js";
const files = {
"app/routes/_index.tsx": String.raw`
import { useState, useEffect } from "react";
import { Link } from "react-router";
export default function IndexRoute() {
const [mounted, setMounted] = useState(false);
useEffect(() => {
setMounted(true);
}, []);
return (
<p data-mounted>Mounted: {mounted ? "yes" : "no"}</p>
);
}
`,
};
test.describe(async () => {
let port: number;
let cwd: string;
let stop: () => void;
test.beforeAll(async () => {
port = await getPort();
cwd = await createProject({
"vite.config.js": await viteConfig.basic({ port }),
...files,
});
stop = await dev({ cwd, port });
});
test.afterAll(() => stop());
test("Vite / dev / route added", async ({ page, browserName }) => {
test.skip(
browserName === "webkit",
"Safari caches too aggressively, browser manifest is cached with old routes"
);
let pageErrors: Error[] = [];
page.on("pageerror", (error) => pageErrors.push(error));
// wait for hydration to make sure initial virtual modules are loaded
await page.goto(`http://localhost:${port}/`, { waitUntil: "networkidle" });
await expect(page.locator("[data-mounted]")).toHaveText("Mounted: yes");
// add new route file
await fs.writeFile(
path.join(cwd, "app/routes/new.tsx"),
String.raw`
export default function Route() {
return (
<div id="new">new route</div>
);
}
`,
"utf-8"
);
// client is not notified of new route addition (https://github.com/remix-run/remix/issues/7894)
// however server can handle new route
await expect
.poll(async () => {
await page.goto(`http://localhost:${port}/new`);
return page.getByText("new route").isVisible();
})
.toBe(true);
});
});