Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
test(canvas,generation): remove timing races from two flaky browser tests (#10314)
Valeri Che546e58df1106
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/GenerateSettingsForm.browser.test.tsx b/invokeai/frontend/webv2/src/features/generation/ui/GenerateSettingsForm.browser.test.tsxindex 91fc6c3832..917ebf9925 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/GenerateSettingsForm.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerateSettingsForm.browser.test.tsx@@ -231,11 +231,14 @@ const buildAdapter = (activeProjectId = 'project-1'): GenerationUiAdapter =>project: { activeProjectId, invocationSourceId: 'generate', showPromptSyntaxHighlighting: false },}) as unknown as GenerationUiAdapter;+// Captured before any test fakes timers, so settling still yields to the browser while a debounce is held.+const realSetTimeout = globalThis.setTimeout;+const settle = (run: () => void = noop, ms = 0) =>act(async () => {run();await new Promise<void>((resolve) => {- globalThis.setTimeout(resolve, ms);+ realSetTimeout(resolve, ms);});});@@ -325,6 +328,7 @@ beforeEach(async () => {afterEach(async () => {await act(() => root?.unmount());+ vi.useRealTimers();host?.remove();host = null;root = null;@@ -814,6 +818,8 @@ describe('GenerateSettingsForm render isolation', () => {});it('flushes a pending edit to its own project on unmount, not on ordinary re-renders', async () => {+ // Holds the debounce, so only a flush can persist the edit, however long the re-renders take on a busy runner.+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });await stepSteps();// A re-render with a new adapter value but the same patch port, as a gallery or queue change causes.await renderAdapter(buildAdapter());diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/StagingBar.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/StagingBar.browser.test.tsxindex c3b7802a6d..5b317cde49 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/StagingBar.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/StagingBar.browser.test.tsx@@ -743,21 +743,30 @@ describe('StagingBar keys', () => {it('leaves keys alone inside its menus: the accept options and a thumbnail menu neither discard nor step', async () => {const onCycle = vi.fn();const onDiscardSelected = vi.fn();- const { thumbnails } = await renderStagingBar(3, 0, noop, noop, noop, makeSlot, { onCycle, onDiscardSelected });+ const onSelectImage = vi.fn();+ const { thumbnails } = await renderStagingBar(3, 0, noop, noop, onSelectImage, makeSlot, {+ onCycle,+ onDiscardSelected,+ });await page.getByRole('button', { name: 'More accept options' }).click();await expect.element(page.getByRole('menu')).toBeVisible();await act(() => userEvent.keyboard('{Delete}{ArrowRight}{Backspace}{ArrowLeft}'));await act(() => userEvent.keyboard('{Escape}'));+ await expect.element(page.getByRole('menu')).not.toBeInTheDocument();await act(() => {thumbnails[0]!.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, cancelable: true }));});- await expect.element(page.getByRole('menu')).toBeVisible();+ await expect.element(page.getByTestId('staging-context-menu')).toBeVisible();+ // Escape left focus on the accept options; the thumbnail's own keys are the ones its menu must hold.+ await act(() => thumbnails[0]!.focus());await act(() => userEvent.keyboard('{Delete}{ArrowRight}{Backspace}{ArrowLeft}'));expect(onDiscardSelected).not.toHaveBeenCalled();expect(onCycle).not.toHaveBeenCalled();+ // Only the right-click's own selection; no arrow moved it.+ expect(onSelectImage.mock.calls).toEqual([[0]]);});it('lets modified presses and other keys through to the workbench', async () => {