Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
markdalgleish committed Jan 4, 2024
1 parent 49613c9 commit dff9f79
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions integration/vite-manifest-invalidation-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test } from "@playwright/test";
import { test, expect } from "@playwright/test";
import getPort from "get-port";

import {
Expand All @@ -20,9 +20,8 @@ const files = {
}, []);
return (
<div id="index">
<div>
<p data-mounted>Mounted: {mounted ? "yes" : "no"}</p>
<p data-hmr>HMR updated: 0</p>
<Link to="/other">/other</Link>
</div>
);
Expand All @@ -36,7 +35,7 @@ const files = {
export default function Route() {
const loaderData = useLoaderData();
return (
<div id="other">loaderData = {JSON.stringify(loaderData)}</div>
<div data-loader-data>loaderData = {JSON.stringify(loaderData)}</div>
);
}
`,
Expand Down Expand Up @@ -66,24 +65,38 @@ test.describe(async () => {
page.on("pageerror", (error) => pageErrors.push(error));
let edit = createEditor(cwd);

// wait hydration to ensure initial manifest is loaded
await page.goto(`http://localhost:${port}/`);
await page.getByText("Mounted: yes").click();
await page.goto(`http://localhost:${port}`, { waitUntil: "networkidle" });
await expect(page.locator("[data-mounted]")).toHaveText("Mounted: yes");
expect(pageErrors).toEqual([]);

// remove loader export in other page should invalidate manifest
await edit("app/routes/other.tsx", (contents) =>
contents.replace(/export const loader.*/, "")
);
let originalContents: string;

// Removing loader export in other page should invalidate manifest
await edit("app/routes/other.tsx", (contents) => {
originalContents = contents;
return contents.replace(/export const loader.*/, "");
});

// after browser reload, client should be aware of there's no loader
// After browser reload, client should be aware that there's no loader on the other route
if (browserName === "webkit") {
// force new page instance for webkit.
// otherwise browser doesn't seem to fetch new manifest probably due to caching.
// Force new page instance for webkit.
// Otherwise browser doesn't seem to fetch new manifest probably due to caching.
page = await context.newPage();
}
await page.goto(`http://localhost:${port}/`);
await page.getByText("Mounted: yes").click();
await page.goto(`http://localhost:${port}`, { waitUntil: "networkidle" });
await expect(page.locator("[data-mounted]")).toHaveText("Mounted: yes");
await page.getByRole("link", { name: "/other" }).click();
await page.getByText("loaderData = null").click();
await expect(page.locator("[data-loader-data]")).toHaveText(
"loaderData = null"
);
expect(pageErrors).toEqual([]);

// Revert route to original state to check HMR works and to ensure the
// original file contents were valid
await edit("app/routes/other.tsx", () => originalContents);
await expect(page.locator("[data-loader-data]")).toHaveText(
'loaderData = "hello"'
);
expect(pageErrors).toEqual([]);
});
});

0 comments on commit dff9f79

Please sign in to comment.