Skip to content

Commit bff9ac8

Browse files
committed
Handle race condition in offscreen route change test
1 parent 67add1f commit bff9ac8

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

integration/vite-route-exports-modified-offscreen-test.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const files = {
3333
export const loader = () => "hello";
3434
3535
export default function Route() {
36-
const loaderData = useLoaderData() ?? null;
36+
const loaderData = useLoaderData();
3737
return (
3838
<div data-loader-data>loaderData = {JSON.stringify(loaderData)}</div>
3939
);
@@ -76,19 +76,24 @@ test.describe(async () => {
7676
originalContents = contents;
7777
return contents.replace(/export const loader.*/, "");
7878
});
79+
// Give the server time to pick the manifest change
80+
await new Promise((resolve) => setTimeout(resolve, 200));
7981

8082
// After browser reload, client should be aware that there's no loader on the other route
8183
if (browserName === "webkit") {
8284
// Force new page instance for webkit.
8385
// Otherwise browser doesn't seem to fetch new manifest probably due to caching.
8486
page = await context.newPage();
8587
}
86-
await page.goto(`http://localhost:${port}`, { waitUntil: "networkidle" });
87-
await expect(page.locator("[data-mounted]")).toHaveText("Mounted: yes");
88-
await page.getByRole("link", { name: "/other" }).click();
89-
await expect(page.locator("[data-loader-data]")).toHaveText(
90-
"loaderData = null"
91-
);
88+
// In case the earlier wait wasn't enough, let the test try again
89+
await expect(async () => {
90+
await page.goto(`http://localhost:${port}`, { waitUntil: "networkidle" });
91+
await expect(page.locator("[data-mounted]")).toHaveText("Mounted: yes");
92+
await page.getByRole("link", { name: "/other" }).click();
93+
await expect(page.locator("[data-loader-data]")).toHaveText(
94+
"loaderData = null"
95+
);
96+
}).toPass();
9297
expect(pageErrors).toEqual([]);
9398

9499
// Revert route to original state to check HMR works and to ensure the

0 commit comments

Comments
 (0)