|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | + |
| 3 | +test.describe("Test N2: VS Code Communication Timeout", () => { |
| 4 | + test.beforeEach(async ({ page }) => { |
| 5 | + await page.goto("/"); |
| 6 | + await page.waitForLoadState("networkidle"); |
| 7 | + }); |
| 8 | + |
| 9 | + test.afterEach(async ({ page }) => { |
| 10 | + // Clean up: reset mock settings |
| 11 | + await page.evaluate(() => { |
| 12 | + const mock = (window as Window & { __vscodeMock?: { clearSilentMessageTypes: () => void; resetResponseDelay: () => void } }).__vscodeMock; |
| 13 | + if (mock) { |
| 14 | + mock.clearSilentMessageTypes(); |
| 15 | + mock.resetResponseDelay(); |
| 16 | + } |
| 17 | + }); |
| 18 | + }); |
| 19 | + |
| 20 | + // Note: saveConfig in dev mode uses synchronous setCurrentData, not sendMessage |
| 21 | + // So we test timeout with operations that actually use sendMessage |
| 22 | + |
| 23 | + test("should show timeout error toast when button set creation times out", async ({ page }) => { |
| 24 | + // Given: Set mock to not respond to createButtonSet messages |
| 25 | + await page.evaluate(() => { |
| 26 | + const mock = (window as Window & { __vscodeMock?: { addSilentMessageType: (type: string) => void } }).__vscodeMock; |
| 27 | + if (mock) { |
| 28 | + mock.addSilentMessageType("createButtonSet"); |
| 29 | + } |
| 30 | + }); |
| 31 | + |
| 32 | + // When: Try to create a new button set |
| 33 | + await page.getByRole("button", { name: "Button Set" }).click(); |
| 34 | + await page.getByRole("menuitem", { name: "Create new set" }).click(); |
| 35 | + await page.getByRole("textbox", { name: "Set Name" }).fill("Timeout Test Set"); |
| 36 | + await page.getByRole("button", { name: "Create" }).click(); |
| 37 | + |
| 38 | + // Then: Timeout error toast should appear |
| 39 | + const toast = page.locator("[data-sonner-toast]", { |
| 40 | + hasText: "Communication with extension timed out", |
| 41 | + }); |
| 42 | + await expect(toast).toBeVisible({ timeout: 7000 }); |
| 43 | + }); |
| 44 | + |
| 45 | + test("should recover after timeout and allow retry", async ({ page }) => { |
| 46 | + // Given: Set mock to not respond to createButtonSet first |
| 47 | + await page.evaluate(() => { |
| 48 | + const mock = (window as Window & { __vscodeMock?: { addSilentMessageType: (type: string) => void } }).__vscodeMock; |
| 49 | + if (mock) { |
| 50 | + mock.addSilentMessageType("createButtonSet"); |
| 51 | + } |
| 52 | + }); |
| 53 | + |
| 54 | + // When: Try to create button set and wait for timeout |
| 55 | + await page.getByRole("button", { name: "Button Set" }).click(); |
| 56 | + await page.getByRole("menuitem", { name: "Create new set" }).click(); |
| 57 | + await page.getByRole("textbox", { name: "Set Name" }).fill("Retry Test Set"); |
| 58 | + await page.getByRole("button", { name: "Create" }).click(); |
| 59 | + |
| 60 | + const timeoutToast = page.locator("[data-sonner-toast]", { |
| 61 | + hasText: "timed out", |
| 62 | + }); |
| 63 | + await expect(timeoutToast).toBeVisible({ timeout: 7000 }); |
| 64 | + |
| 65 | + // Clear silent mode |
| 66 | + await page.evaluate(() => { |
| 67 | + const mock = (window as Window & { __vscodeMock?: { clearSilentMessageTypes: () => void } }).__vscodeMock; |
| 68 | + if (mock) { |
| 69 | + mock.clearSilentMessageTypes(); |
| 70 | + } |
| 71 | + }); |
| 72 | + |
| 73 | + // Wait for timeout toast to disappear |
| 74 | + await timeoutToast.waitFor({ state: "hidden", timeout: 10000 }); |
| 75 | + |
| 76 | + // Retry - should succeed now |
| 77 | + await page.getByRole("button", { name: "Create" }).click(); |
| 78 | + |
| 79 | + // Then: Success toast should appear |
| 80 | + const successToast = page.locator("[data-sonner-toast]", { |
| 81 | + hasText: 'Button set "Retry Test Set" created', |
| 82 | + }); |
| 83 | + await expect(successToast).toBeVisible({ timeout: 3000 }); |
| 84 | + }); |
| 85 | + |
| 86 | + test("should log timeout error to console", async ({ page }) => { |
| 87 | + // Set up console listener |
| 88 | + const consoleMessages: string[] = []; |
| 89 | + page.on("console", (msg) => { |
| 90 | + if (msg.type() === "error") { |
| 91 | + consoleMessages.push(msg.text()); |
| 92 | + } |
| 93 | + }); |
| 94 | + |
| 95 | + // Given: Set mock to not respond |
| 96 | + await page.evaluate(() => { |
| 97 | + const mock = (window as Window & { __vscodeMock?: { addSilentMessageType: (type: string) => void } }).__vscodeMock; |
| 98 | + if (mock) { |
| 99 | + mock.addSilentMessageType("createButtonSet"); |
| 100 | + } |
| 101 | + }); |
| 102 | + |
| 103 | + // When: Try to create button set |
| 104 | + await page.getByRole("button", { name: "Button Set" }).click(); |
| 105 | + await page.getByRole("menuitem", { name: "Create new set" }).click(); |
| 106 | + await page.getByRole("textbox", { name: "Set Name" }).fill("Console Test"); |
| 107 | + await page.getByRole("button", { name: "Create" }).click(); |
| 108 | + |
| 109 | + // Wait for timeout |
| 110 | + await page.waitForTimeout(6000); |
| 111 | + |
| 112 | + // Then: Error should be logged |
| 113 | + expect(consoleMessages.some((msg) => msg.includes("Communication with extension timed out"))).toBe(true); |
| 114 | + }); |
| 115 | + |
| 116 | + test("should handle slow but successful response", async ({ page }) => { |
| 117 | + // Given: Set mock to respond slowly (but within timeout) |
| 118 | + await page.evaluate(() => { |
| 119 | + const mock = (window as Window & { __vscodeMock?: { setResponseDelay: (delay: number) => void } }).__vscodeMock; |
| 120 | + if (mock) { |
| 121 | + mock.setResponseDelay(2000); // 2 seconds delay |
| 122 | + } |
| 123 | + }); |
| 124 | + |
| 125 | + // When: Create a button set (uses sendMessage unlike save) |
| 126 | + await page.getByRole("button", { name: "Button Set" }).click(); |
| 127 | + await page.getByRole("menuitem", { name: "Create new set" }).click(); |
| 128 | + await page.getByRole("textbox", { name: "Set Name" }).fill("Slow Response Test"); |
| 129 | + await page.getByRole("button", { name: "Create" }).click(); |
| 130 | + |
| 131 | + // Then: Should eventually show success (not timeout) |
| 132 | + const successToast = page.locator("[data-sonner-toast]", { |
| 133 | + hasText: 'Button set "Slow Response Test" created', |
| 134 | + }); |
| 135 | + await expect(successToast).toBeVisible({ timeout: 5000 }); |
| 136 | + |
| 137 | + // No timeout toast should appear |
| 138 | + const timeoutToast = page.locator("[data-sonner-toast]", { |
| 139 | + hasText: "timed out", |
| 140 | + }); |
| 141 | + await expect(timeoutToast).not.toBeVisible(); |
| 142 | + }); |
| 143 | +}); |
0 commit comments