From f306cc9bcbd41446633d7f1ad82726a0a436f48e Mon Sep 17 00:00:00 2001 From: bymyself Date: Thu, 6 Nov 2025 19:49:48 -0700 Subject: [PATCH] refactor: Extract comfyPageFixture to separate file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes circular dependency between ComfyPage and LocalhostComfyPage. Changes: - Create browser_tests/fixtures/comfyPageFixture.ts with fixture - Remove fixture from ComfyPage.ts (keep abstract class only) - Re-export fixture from ComfyPage.ts for backward compatibility Now properly follows dependency hierarchy: - ComfyPage.ts (abstract) - no implementation imports - LocalhostComfyPage.ts → imports ComfyPage - comfyPageFixture.ts → imports both - Tests import from ComfyPage.ts (re-exported) --- browser_tests/fixtures/ComfyPage.ts | 51 ++------------------ browser_tests/fixtures/comfyPageFixture.ts | 56 ++++++++++++++++++++++ 2 files changed, 59 insertions(+), 48 deletions(-) create mode 100644 browser_tests/fixtures/comfyPageFixture.ts diff --git a/browser_tests/fixtures/ComfyPage.ts b/browser_tests/fixtures/ComfyPage.ts index 5c5e3364d..868cde55d 100644 --- a/browser_tests/fixtures/ComfyPage.ts +++ b/browser_tests/fixtures/ComfyPage.ts @@ -1,5 +1,5 @@ import type { APIRequestContext, Locator, Page } from '@playwright/test' -import { test as base, expect } from '@playwright/test' +import { expect } from '@playwright/test' import dotenv from 'dotenv' import * as fs from 'fs' @@ -7,11 +7,8 @@ import type { LGraphNode } from '../../src/lib/litegraph/src/litegraph' import type { NodeId } from '../../src/platform/workflow/validation/schemas/workflowSchema' import type { KeyCombo } from '../../src/schemas/keyBindingSchema' import type { useWorkspaceStore } from '../../src/stores/workspaceStore' -import { NodeBadgeMode } from '../../src/types/nodeSource' import { ComfyActionbar } from '../helpers/actionbar' import { ComfyTemplates } from '../helpers/templates' -import { ComfyMouse } from './ComfyMouse' -import { LocalhostComfyPage } from './LocalhostComfyPage' import { VueNodeHelpers } from './VueNodeHelpers' import { ComfyNodeSearchBox } from './components/ComfyNodeSearchBox' import { SettingDialog } from './components/SettingDialog' @@ -1594,50 +1591,8 @@ export abstract class ComfyPage { export const testComfySnapToGridGridSize = 50 -export const comfyPageFixture = base.extend<{ - comfyPage: ComfyPage - comfyMouse: ComfyMouse -}>({ - comfyPage: async ({ page, request }, use, testInfo) => { - const comfyPage = new LocalhostComfyPage(page, request) - - const { parallelIndex } = testInfo - const username = `playwright-test-${parallelIndex}` - const userId = await comfyPage.setupUser(username) - if (userId) { - comfyPage.userIds[parallelIndex] = userId - } - - try { - await comfyPage.setupSettings({ - 'Comfy.UseNewMenu': 'Top', - // Hide canvas menu/info/selection toolbox by default. - 'Comfy.Graph.CanvasInfo': false, - 'Comfy.Graph.CanvasMenu': false, - 'Comfy.Canvas.SelectionToolbox': false, - // Hide all badges by default. - 'Comfy.NodeBadge.NodeIdBadgeMode': NodeBadgeMode.None, - 'Comfy.NodeBadge.NodeSourceBadgeMode': NodeBadgeMode.None, - // Disable tooltips by default to avoid flakiness. - 'Comfy.EnableTooltips': false, - 'Comfy.userId': userId, - // Set tutorial completed to true to avoid loading the tutorial workflow. - 'Comfy.TutorialCompleted': true, - 'Comfy.SnapToGrid.GridSize': testComfySnapToGridGridSize, - 'Comfy.VueNodes.AutoScaleLayout': false - }) - } catch (e) { - console.error(e) - } - - await comfyPage.setup() - await use(comfyPage) - }, - comfyMouse: async ({ comfyPage }, use) => { - const comfyMouse = new ComfyMouse(comfyPage) - await use(comfyMouse) - } -}) +// Re-export fixture from separate file to avoid circular dependencies +export { comfyPageFixture } from './comfyPageFixture' const makeMatcher = function ( getValue: (node: NodeReference) => Promise | T, diff --git a/browser_tests/fixtures/comfyPageFixture.ts b/browser_tests/fixtures/comfyPageFixture.ts new file mode 100644 index 000000000..bb74c4214 --- /dev/null +++ b/browser_tests/fixtures/comfyPageFixture.ts @@ -0,0 +1,56 @@ +import { test as base } from '@playwright/test' + +import { NodeBadgeMode } from '../../src/types/nodeSource' +import type { ComfyPage } from './ComfyPage' +import { testComfySnapToGridGridSize } from './ComfyPage' +import { ComfyMouse } from './ComfyMouse' +import { LocalhostComfyPage } from './LocalhostComfyPage' + +/** + * Localhost fixture for ComfyPage. + * Creates a test user and sets up default settings for stable testing. + */ +export const comfyPageFixture = base.extend<{ + comfyPage: ComfyPage + comfyMouse: ComfyMouse +}>({ + comfyPage: async ({ page, request }, use, testInfo) => { + const comfyPage = new LocalhostComfyPage(page, request) + + const { parallelIndex } = testInfo + const username = `playwright-test-${parallelIndex}` + const userId = await comfyPage.setupUser(username) + if (userId) { + comfyPage.userIds[parallelIndex] = userId + } + + try { + await comfyPage.setupSettings({ + 'Comfy.UseNewMenu': 'Top', + // Hide canvas menu/info/selection toolbox by default. + 'Comfy.Graph.CanvasInfo': false, + 'Comfy.Graph.CanvasMenu': false, + 'Comfy.Canvas.SelectionToolbox': false, + // Hide all badges by default. + 'Comfy.NodeBadge.NodeIdBadgeMode': NodeBadgeMode.None, + 'Comfy.NodeBadge.NodeSourceBadgeMode': NodeBadgeMode.None, + // Disable tooltips by default to avoid flakiness. + 'Comfy.EnableTooltips': false, + 'Comfy.userId': userId, + // Set tutorial completed to true to avoid loading the tutorial workflow. + 'Comfy.TutorialCompleted': true, + 'Comfy.SnapToGrid.GridSize': testComfySnapToGridGridSize, + 'Comfy.VueNodes.AutoScaleLayout': false + }) + } catch (e) { + console.error(e) + } + + await comfyPage.setup() + await use(comfyPage) + }, + comfyMouse: async ({ comfyPage }, use) => { + const comfyMouse = new ComfyMouse(comfyPage) + await use(comfyMouse) + } +})