Skip to content

Commit b8cab67

Browse files
authored
tests: Fix flaky Vue HMR test. (#33)
1 parent ce8e84f commit b8cab67

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

‎packages/vue/test/integration/vue-pages-client.test.ts‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,30 @@ afterAll(async () => {
2121
await browser?.close();
2222
});
2323

24+
async function prepareForViteHmr(page: Page) {
25+
await page.addInitScript(() => {
26+
const marker = "__void_vite_connected";
27+
const patched = "__void_vite_console_patched";
28+
if ((window as any)[patched]) return;
29+
30+
const originalDebug = console.debug.bind(console);
31+
console.debug = (...args: unknown[]) => {
32+
if (args.some((arg) => typeof arg === "string" && arg.includes("[vite] connected."))) {
33+
(window as any)[marker] = true;
34+
}
35+
originalDebug(...args);
36+
};
37+
38+
(window as any)[patched] = true;
39+
});
40+
}
41+
42+
async function waitForViteHmr(page: Page) {
43+
await page.waitForFunction(() => (window as any).__void_vite_connected === true, {
44+
timeout: 15_000,
45+
});
46+
}
47+
2448
function defineClientTests(getBase: () => string) {
2549
let BASE: string;
2650
beforeAll(() => {
@@ -657,8 +681,10 @@ describe("vue-pages client (dev)", () => {
657681
page.setDefaultTimeout(10_000);
658682

659683
try {
684+
await prepareForViteHmr(page);
660685
await page.goto(`${DEV_BASE}/deferred`);
661686
await page.waitForSelector('#app[data-hydrated="true"]');
687+
await waitForViteHmr(page);
662688
await page.waitForFunction(
663689
() => document.querySelector("h1")?.textContent === "Deferred Page",
664690
);
@@ -727,8 +753,10 @@ describe("vue-pages client (dev)", () => {
727753
page.setDefaultTimeout(10_000);
728754

729755
try {
756+
await prepareForViteHmr(page);
730757
await page.goto(`${DEV_BASE}/blog`);
731758
await page.waitForSelector('[data-island][data-hydrated="true"]');
759+
await waitForViteHmr(page);
732760

733761
// Interact to establish client state — count becomes 1
734762
await page.click("button:has-text('Increment')");
@@ -748,7 +776,7 @@ describe("vue-pages client (dev)", () => {
748776
// Wait for HMR to update the component text
749777
await page.waitForFunction(
750778
() => document.querySelector('[data-testid="count"]')?.textContent?.startsWith("Total:"),
751-
{ timeout: 10_000 },
779+
{ timeout: 15_000 },
752780
);
753781

754782
// No full page reload — window marker should still be set

0 commit comments

Comments
 (0)