Skip to content

Commit 7f4a4cb

Browse files
authored
test(fullstack): test vue-router (#1187)
1 parent 61e7f24 commit 7f4a4cb

File tree

2 files changed

+87
-17
lines changed

2 files changed

+87
-17
lines changed

packages/fullstack/e2e/basic.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ function defineTest(f: Fixture) {
8787
if (f.mode === "dev") {
8888
test("hmr react", async ({ page }) => {
8989
await page.goto(f.url());
90+
await waitForHydration(page, "main");
9091
await using _ = await expectNoReload(page);
9192

9293
await expect(
@@ -112,6 +113,7 @@ function defineTest(f: Fixture) {
112113

113114
test("hmr css", async ({ page }) => {
114115
await page.goto(f.url());
116+
await waitForHydration(page, "main");
115117
await using _ = await expectNoReload(page);
116118

117119
await expect(

packages/fullstack/e2e/vue-router.test.ts

Lines changed: 85 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect, test } from "@playwright/test";
1+
import { type Page, expect, test } from "@playwright/test";
22
import { type Fixture, useFixture } from "./fixture";
33
import { expectNoReload, waitForHydration } from "./helper";
44

@@ -36,24 +36,92 @@ function defineTest(f: Fixture) {
3636
await waitForHydration(page, "#root");
3737
expect(errors).toEqual([]); // no hydration mismatch
3838

39-
// client
40-
await expect(page.locator(".counter-card")).toContainText("Count: 0");
41-
await page.getByRole("button", { name: "Increment" }).click();
42-
await expect(page.locator(".counter-card")).toContainText("Count: 1");
43-
44-
// css
45-
// - styles.css
46-
await expect(page.getByRole("button", { name: "Increment" })).toHaveCSS(
47-
"background-color",
48-
"rgb(83, 91, 242)",
49-
);
50-
// - index.vue (scoped css)
51-
await expect(
52-
page.getByRole("heading", { name: "Vue Router Custom Framework" }),
53-
).toHaveCSS("color", "rgb(100, 108, 255)");
39+
await testClient(page);
40+
await testCss(page);
41+
await testNavigation(page);
5442

5543
expect(errors).toEqual([]);
5644
});
5745

58-
// TODO: hmr
46+
test.describe(() => {
47+
test.use({ javaScriptEnabled: false });
48+
49+
test("ssr", async ({ page }) => {
50+
await page.goto(f.url());
51+
await expect(page.locator(".counter-card")).toContainText("Count: 0");
52+
await testCss(page);
53+
if (f.mode === "build") {
54+
await expect(
55+
page.locator("link[rel='modulepreload']").first(),
56+
).toBeAttached();
57+
}
58+
});
59+
});
60+
61+
if (f.mode === "dev") {
62+
test("hmr vue", async ({ page }) => {
63+
await page.goto(f.url());
64+
await waitForHydration(page, "#root");
65+
await using _ = await expectNoReload(page);
66+
67+
await testClient(page);
68+
69+
const jsFile = f.createEditor("src/routes/index.vue");
70+
jsFile.edit((s) => s.replace("Count:", "Count-edit:"));
71+
72+
await expect(page.locator(".counter-card")).toContainText(
73+
"Count-edit: 1",
74+
);
75+
76+
jsFile.reset();
77+
await expect(page.locator(".counter-card")).toContainText("Count: 1");
78+
79+
await testCss(page);
80+
});
81+
82+
test("hmr css", async ({ page }) => {
83+
await page.goto(f.url());
84+
await waitForHydration(page, "#root");
85+
await using _ = await expectNoReload(page);
86+
87+
await testClient(page);
88+
89+
// scoped css
90+
const cssFile = f.createEditor("src/routes/index.vue");
91+
cssFile.edit((s) =>
92+
s.replace("color: rgb(100, 108, 255);", "color: rgb(0, 0, 255);"),
93+
);
94+
await expect(
95+
page.getByRole("heading", { name: "Vue Router Custom Framework" }),
96+
).toHaveCSS("color", "rgb(0, 0, 255)");
97+
cssFile.reset();
98+
99+
// css is restored
100+
await testCss(page);
101+
});
102+
}
103+
}
104+
105+
async function testClient(page: Page) {
106+
await expect(page.locator(".counter-card")).toContainText("Count: 0");
107+
await page.getByRole("button", { name: "Increment" }).click();
108+
await expect(page.locator(".counter-card")).toContainText("Count: 1");
109+
}
110+
111+
async function testCss(page: Page) {
112+
// styles.css
113+
await expect(page.getByRole("button", { name: "Increment" })).toHaveCSS(
114+
"background-color",
115+
"rgb(83, 91, 242)",
116+
);
117+
// index.vue (scoped css)
118+
await expect(
119+
page.getByRole("heading", { name: "Vue Router Custom Framework" }),
120+
).toHaveCSS("color", "rgb(100, 108, 255)");
121+
}
122+
123+
async function testNavigation(page: Page) {
124+
await page.getByRole("link", { name: "About" }).click();
125+
await page.waitForURL("**/about");
126+
await expect(page.getByRole("heading", { name: "About" })).toBeVisible();
59127
}

0 commit comments

Comments
 (0)