|
1 | | -import { expect, test } from "@playwright/test"; |
| 1 | +import { type Page, expect, test } from "@playwright/test"; |
2 | 2 | import { type Fixture, useFixture } from "./fixture"; |
3 | 3 | import { expectNoReload, waitForHydration } from "./helper"; |
4 | 4 |
|
@@ -36,24 +36,92 @@ function defineTest(f: Fixture) { |
36 | 36 | await waitForHydration(page, "#root"); |
37 | 37 | expect(errors).toEqual([]); // no hydration mismatch |
38 | 38 |
|
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); |
54 | 42 |
|
55 | 43 | expect(errors).toEqual([]); |
56 | 44 | }); |
57 | 45 |
|
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(); |
59 | 127 | } |
0 commit comments