|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | +import { type Fixture, useFixture } from "./fixture"; |
| 3 | +import { expectNoReload, waitForHydration } from "./helper"; |
| 4 | + |
| 5 | +test.describe("dev", () => { |
| 6 | + const f = useFixture({ root: "examples/vue-router", mode: "dev" }); |
| 7 | + defineTest(f); |
| 8 | +}); |
| 9 | + |
| 10 | +test.describe("build", () => { |
| 11 | + const f = useFixture({ root: "examples/vue-router", mode: "build" }); |
| 12 | + defineTest(f); |
| 13 | +}); |
| 14 | + |
| 15 | +test.describe("build ssg", () => { |
| 16 | + const f = useFixture({ |
| 17 | + root: "examples/vue-router", |
| 18 | + mode: "build", |
| 19 | + command: "pnpm preview-ssg", |
| 20 | + buildCommand: "pnpm build-ssg", |
| 21 | + }); |
| 22 | + defineTest(f); |
| 23 | +}); |
| 24 | + |
| 25 | +function defineTest(f: Fixture) { |
| 26 | + test("basic", async ({ page }) => { |
| 27 | + await page.goto(f.url()); |
| 28 | + await using _ = await expectNoReload(page); |
| 29 | + |
| 30 | + const errors: Error[] = []; |
| 31 | + page.on("pageerror", (error) => { |
| 32 | + errors.push(error); |
| 33 | + }); |
| 34 | + |
| 35 | + // hydration |
| 36 | + await waitForHydration(page, "#root"); |
| 37 | + expect(errors).toEqual([]); // no hydration mismatch |
| 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)"); |
| 54 | + |
| 55 | + expect(errors).toEqual([]); |
| 56 | + }); |
| 57 | + |
| 58 | + // TODO: hmr |
| 59 | +} |
0 commit comments