From 0bcec597b419727c774ccaf22f8eea36039247fa Mon Sep 17 00:00:00 2001 From: d-oit Date: Fri, 5 Jun 2026 17:28:40 +0200 Subject: [PATCH] fix(tests): stabilize flaky command palette E2E test Wait for input toBeFocused() after opening palette before pressing Escape. CommandPalette uses setTimeout(10ms) to focus input, so Escape was sometimes sent before focus arrived. 5/5 consecutive runs pass (was ~1/3 failure rate). Co-authored-by: d-oit <6849456+d-oit@users.noreply.github.com> --- tests/e2e/modern-shell.spec.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/e2e/modern-shell.spec.ts b/tests/e2e/modern-shell.spec.ts index b9abafb4..c63c3e59 100644 --- a/tests/e2e/modern-shell.spec.ts +++ b/tests/e2e/modern-shell.spec.ts @@ -13,19 +13,21 @@ test.describe('Modern Shell UX', () => { // Toggle on await page.keyboard.press('Control+k'); await expect(palette).toBeVisible(); + // Wait for input focus (palette uses setTimeout 10ms to focus input) + await expect(page.locator('.command-palette-header input')).toBeFocused({ timeout: 3000 }); // Toggle off with Escape await page.keyboard.press('Escape'); - await expect(palette).not.toBeVisible(); + await expect(palette).not.toBeVisible({ timeout: 5000 }); // Toggle on again await page.keyboard.press('Control+k'); await expect(palette).toBeVisible(); + await expect(page.locator('.command-palette-header input')).toBeFocused({ timeout: 3000 }); // Toggle off by clicking overlay - // Use dispatchEvent for more reliable overlay clicks across viewports await page.locator('.command-palette-overlay').evaluate(el => (el as HTMLElement).click()); - await expect(palette).not.toBeVisible(); + await expect(palette).not.toBeVisible({ timeout: 5000 }); }); test('searching and keyboard navigation in palette', async ({ page }) => {