Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix normalizeReferenceId #99

Merged
merged 3 commits into from
Jul 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test: test client reference module matches browser hmr module
  • Loading branch information
hi-ogawa committed Jul 22, 2024
commit 21a3db81c6542a15e3e662426d724f8deedfc3a3
52 changes: 49 additions & 3 deletions examples/react-server/e2e/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,24 @@ test("client hmr @dev", async ({ page }) => {
await waitForHydration(page);

using editor = createEditor("src/routes/_client.tsx");
await using reloadChecker = await createReloadChecker(page);

await page.getByRole("heading", { name: "Hello Client Component" }).click();
await page.getByTestId("client-component").getByText("Count: 0").click();
await page
.getByTestId("client-component")
.getByRole("button", { name: "+" })
.click();
await page.getByTestId("client-component").getByText("Count: 1").click();
editor.edit((s) =>
s.replace("Hello Client Component", "Hello [EDIT] Client Component"),
);
await page
.getByRole("heading", { name: "Hello [EDIT] Client Component" })
.click();
await page.getByTestId("client-component").getByText("Count: 1").click();

await reloadChecker.check();
const res = await page.reload();
await waitForHydration(page);
await reloadChecker.reset();
const resText = await res?.text();
expect(resText).toContain("Hello [EDIT] Client Component");
});
Expand Down Expand Up @@ -91,6 +95,48 @@ test("shared hmr @dev", async ({ page }) => {
expect(resText).toContain("Shared [EDIT] Component (<!-- -->client<!-- -->)");
});

// this is a test to make sure client reference points to the
// same module as the last browser hmr module
// cf. https://github.com/hi-ogawa/vite-plugins/pull/316
test("mixed hmr @dev", async ({ page }) => {
usePageErrorChecker(page);
await page.goto("/");
await waitForHydration(page);

// browser hmr
using clientFile = createEditor("src/routes/_client.tsx");
await page.getByRole("heading", { name: "Hello Client Component" }).click();
await page.getByTestId("client-component").getByText("Count: 0").click();
await page
.getByTestId("client-component")
.getByRole("button", { name: "+" })
.click();
await page.getByTestId("client-component").getByText("Count: 1").click();
clientFile.edit((s) =>
s.replace("Hello Client Component", "Hello [EDIT] Client Component"),
);
await page
.getByRole("heading", { name: "Hello [EDIT] Client Component" })
.click();
await page.getByTestId("client-component").getByText("Count: 1").click();

// server hmr
using serverFile = createEditor("src/routes/layout.tsx");
await page.getByRole("heading", { name: "Hello Server Component" }).click();
serverFile.edit((s) =>
s.replace("Hello Server Component", "Hello [EDIT] Server Component"),
);
await page
.getByRole("heading", { name: "Hello [EDIT] Server Component" })
.click();

// client component state should be preserved
await page
.getByRole("heading", { name: "Hello [EDIT] Client Component" })
.click();
await page.getByTestId("client-component").getByText("Count: 1").click();
});

test("server action 1 @js", async ({ page }) => {
usePageErrorChecker(page);
await page.goto("/action");
Expand Down
Loading