diff --git a/src/components/TopMenuSection.test.ts b/src/components/TopMenuSection.test.ts index 945c7311108..51f6caf2e91 100644 --- a/src/components/TopMenuSection.test.ts +++ b/src/components/TopMenuSection.test.ts @@ -27,7 +27,7 @@ const mockData = vi.hoisted(() => ({ setShowConflictRedDot: (_value: boolean) => {} })) -vi.mock('@/composables/auth/useCurrentUser', () => ({ +vi.mock(import('@/composables/auth/useCurrentUser'), () => ({ useCurrentUser: () => { return { isLoggedIn: computed(() => mockData.isLoggedIn) @@ -35,19 +35,20 @@ vi.mock('@/composables/auth/useCurrentUser', () => ({ } })) -vi.mock('@/platform/distribution/types', () => ({ +vi.mock(import('@/platform/distribution/types'), () => ({ isCloud: false, isNightly: false })) -vi.mock('@/platform/updates/common/releaseStore', () => ({ +vi.mock(import('@/platform/updates/common/releaseStore'), () => ({ useReleaseStore: () => ({ shouldShowRedDot: computed(() => true) }) })) -vi.mock( - '@/workbench/extensions/manager/composables/useConflictAcknowledgment', +vi.mock( + import('@/workbench/extensions/manager/composables/useConflictAcknowledgment'), + () => { const shouldShowConflictRedDot = ref(false) mockData.setShowConflictRedDot = (value: boolean) => { @@ -62,21 +63,25 @@ vi.mock( } ) -vi.mock('@/workbench/extensions/manager/composables/useManagerState', () => ({ - useManagerState: () => ({ - shouldShowManagerButtons: computed(() => true), - openManager: vi.fn() +vi.mock( + import('@/workbench/extensions/manager/composables/useManagerState'), + + () => ({ + useManagerState: () => ({ + shouldShowManagerButtons: computed(() => true), + openManager: vi.fn() + }) }) -})) +) -vi.mock('@/stores/authStore', () => ({ +vi.mock(import('@/stores/authStore'), () => ({ useAuthStore: vi.fn(() => ({ currentUser: null, loading: false })) })) -vi.mock('@/scripts/app', () => ({ +vi.mock(import('@/scripts/app'), () => ({ app: { menu: { element: document.createElement('div') @@ -86,7 +91,7 @@ vi.mock('@/scripts/app', () => ({ const mockTrackUiButtonClicked = vi.hoisted(() => vi.fn()) -vi.mock('@/platform/telemetry', () => ({ +vi.mock(import('@/platform/telemetry'), () => ({ useTelemetry: () => ({ trackUiButtonClicked: mockTrackUiButtonClicked }) diff --git a/src/components/actionbar/BatchCountEdit.test.ts b/src/components/actionbar/BatchCountEdit.test.ts index db6e55d74e1..2377ce48e56 100644 --- a/src/components/actionbar/BatchCountEdit.test.ts +++ b/src/components/actionbar/BatchCountEdit.test.ts @@ -10,7 +10,7 @@ import BatchCountEdit from './BatchCountEdit.vue' const maxBatchCount = 16 -vi.mock('@/platform/settings/settingStore', () => ({ +vi.mock(import('@/platform/settings/settingStore'), () => ({ useSettingStore: () => ({ get: (settingId: string) => settingId === 'Comfy.QueueButton.BatchCountLimit' ? maxBatchCount : 1 diff --git a/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.test.ts b/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.test.ts index 48b7687c5cb..892f1a9f10d 100644 --- a/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.test.ts +++ b/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.test.ts @@ -23,26 +23,31 @@ const state = vi.hoisted(() => ({ updateDialog: vi.fn() })) -vi.mock('@/composables/billing/useBillingContext', async () => { - const { computed } = await import('vue') - return { - useBillingContext: () => ({ - canRunWorkflows: mockCanRunWorkflows, - showsSubscribeToRunPrompt: computed( - () => mockIsInitialized.value && !mockCanRunWorkflows.value - ), - billingStatus: mockBillingStatus, - subscription: computed(() => - mockSubscriptionTier.value ? { tier: mockSubscriptionTier.value } : null - ), - manageSubscription: state.manageSubscription, - fetchStatus: state.fetchStatus, - fetchBalance: state.fetchBalance - }) +vi.mock( + import('@/composables/billing/useBillingContext'), + async () => { + const { computed } = await import('vue') + return { + useBillingContext: () => ({ + canRunWorkflows: mockCanRunWorkflows, + showsSubscribeToRunPrompt: computed( + () => mockIsInitialized.value && !mockCanRunWorkflows.value + ), + billingStatus: mockBillingStatus, + subscription: computed(() => + mockSubscriptionTier.value + ? { tier: mockSubscriptionTier.value } + : null + ), + manageSubscription: state.manageSubscription, + fetchStatus: state.fetchStatus, + fetchBalance: state.fetchBalance + }) + } } -}) +) -vi.mock('@/composables/useFeatureFlags', () => ({ +vi.mock(import('@/composables/useFeatureFlags'), () => ({ useFeatureFlags: () => ({ flags: { get v1PaymentRecovery() { @@ -52,48 +57,57 @@ vi.mock('@/composables/useFeatureFlags', () => ({ }) })) -vi.mock('@/composables/useErrorHandling', () => ({ +vi.mock(import('@/composables/useErrorHandling'), () => ({ useErrorHandling: () => ({ toastErrorHandler: state.toastErrorHandler }) })) -vi.mock('@/platform/workspace/composables/useWorkspaceUI', async () => { - const { computed } = await import('vue') - return { - useWorkspaceUI: () => ({ - permissions: computed(() => ({ - canManageSubscription: state.canManageSubscription - })) - }) +vi.mock( + import('@/platform/workspace/composables/useWorkspaceUI'), + async () => { + const { computed } = await import('vue') + return { + useWorkspaceUI: () => ({ + permissions: computed(() => ({ + canManageSubscription: state.canManageSubscription + })) + }) + } } -}) +) -vi.mock('@/services/dialogService', () => ({ +vi.mock(import('@/services/dialogService'), () => ({ useDialogService: () => ({ showLayoutDialog: state.showLayoutDialog }) })) -vi.mock('@/stores/dialogStore', () => ({ +vi.mock(import('@/stores/dialogStore'), () => ({ useDialogStore: () => ({ closeDialog: state.closeDialog, updateDialog: state.updateDialog }) })) -vi.mock('@/components/actionbar/ComfyRunButton/ComfyQueueButton.vue', () => ({ - default: { - name: 'ComfyQueueButton', - props: ['paymentRecoveryLock'], - emits: ['paymentRecoveryClick'], - template: - '
' - } -})) - -vi.mock('@/platform/cloud/subscription/components/SubscribeToRun.vue', () => ({ - default: { - name: 'SubscribeToRun', - template: '
' - } -})) +vi.mock( + import('@/components/actionbar/ComfyRunButton/ComfyQueueButton.vue'), + () => ({ + default: { + name: 'ComfyQueueButton', + props: ['paymentRecoveryLock'], + emits: ['paymentRecoveryClick'], + template: + '
' + } + }) +) + +vi.mock( + import('@/platform/cloud/subscription/components/SubscribeToRun.vue'), + () => ({ + default: { + name: 'SubscribeToRun', + template: '
' + } + }) +) function renderWrapper() { return render(CloudRunButtonWrapper) diff --git a/src/components/actionbar/ComfyRunButton/ComfyQueueButton.test.ts b/src/components/actionbar/ComfyRunButton/ComfyQueueButton.test.ts index 83640e9fdb2..2b12816f783 100644 --- a/src/components/actionbar/ComfyRunButton/ComfyQueueButton.test.ts +++ b/src/components/actionbar/ComfyRunButton/ComfyQueueButton.test.ts @@ -23,15 +23,15 @@ import userEvent from '@testing-library/user-event' import ComfyQueueButton from './ComfyQueueButton.vue' -vi.mock('@/platform/distribution/types', () => ({ +vi.mock(import('@/platform/distribution/types'), () => ({ isCloud: false })) -vi.mock('@/platform/telemetry', () => ({ +vi.mock(import('@/platform/telemetry'), () => ({ useTelemetry: () => null })) -vi.mock('@/stores/workspaceStore', () => ({ +vi.mock(import('@/stores/workspaceStore'), () => ({ useWorkspaceStore: () => ({ shiftDown: false }) diff --git a/src/components/appMode/AppModeToolbar.test.ts b/src/components/appMode/AppModeToolbar.test.ts index 902a1142714..d766fa8f4bd 100644 --- a/src/components/appMode/AppModeToolbar.test.ts +++ b/src/components/appMode/AppModeToolbar.test.ts @@ -11,11 +11,11 @@ const appModeState = vi.hoisted(() => ({ })) const enterBuilder = vi.hoisted(() => vi.fn()) -vi.mock('@/composables/useAppMode', () => ({ +vi.mock(import('@/composables/useAppMode'), () => ({ useAppMode: () => ({ enableAppBuilder: appModeState.enableAppBuilder }) })) -vi.mock('@/stores/appModeStore', async () => { +vi.mock(import('@/stores/appModeStore'), async () => { const { computed, reactive } = await import('vue') return { useAppModeStore: () => diff --git a/src/components/bottomPanel/tabs/shortcuts/EssentialsPanel.test.ts b/src/components/bottomPanel/tabs/shortcuts/EssentialsPanel.test.ts index 59f58754c5a..de78d477d72 100644 --- a/src/components/bottomPanel/tabs/shortcuts/EssentialsPanel.test.ts +++ b/src/components/bottomPanel/tabs/shortcuts/EssentialsPanel.test.ts @@ -4,14 +4,17 @@ import { describe, expect, it, vi } from 'vitest' import type { ComfyCommandImpl } from '@/stores/commandStore' // Mock ShortcutsList component -vi.mock('@/components/bottomPanel/tabs/shortcuts/ShortcutsList.vue', () => ({ - default: { - name: 'ShortcutsList', - props: ['commands', 'subcategories', 'columns'], - template: - '
{{ JSON.stringify(subcategories) }}
' - } -})) +vi.mock( + import('@/components/bottomPanel/tabs/shortcuts/ShortcutsList.vue'), + () => ({ + default: { + name: 'ShortcutsList', + props: ['commands', 'subcategories', 'columns'], + template: + '
{{ JSON.stringify(subcategories) }}
' + } + }) +) // Mock command store const mockCommands: ComfyCommandImpl[] = [ @@ -42,7 +45,7 @@ const mockCommands: ComfyCommandImpl[] = [ } ] -vi.mock('@/stores/commandStore', () => ({ +vi.mock(import('@/stores/commandStore'), () => ({ useCommandStore: () => ({ commands: mockCommands }) diff --git a/src/components/bottomPanel/tabs/shortcuts/ShortcutsList.test.ts b/src/components/bottomPanel/tabs/shortcuts/ShortcutsList.test.ts index 8af267d84a5..e2800483ea9 100644 --- a/src/components/bottomPanel/tabs/shortcuts/ShortcutsList.test.ts +++ b/src/components/bottomPanel/tabs/shortcuts/ShortcutsList.test.ts @@ -1,29 +1,35 @@ -import { describe, expect, it, vi } from 'vitest' +import { describe, expect, it } from 'vitest' +import { createI18n } from 'vue-i18n' import { render, screen } from '@testing-library/vue' import ShortcutsList from '@/components/bottomPanel/tabs/shortcuts/ShortcutsList.vue' import type { ComfyCommandImpl } from '@/stores/commandStore' -// Mock vue-i18n -const mockT = vi.fn((key: string) => { - const translations: Record = { - 'shortcuts.subcategories.workflow': 'Workflow', - 'shortcuts.subcategories.node': 'Node', - 'shortcuts.subcategories.queue': 'Queue', - 'shortcuts.subcategories.view': 'View', - 'shortcuts.subcategories.panelControls': 'Panel Controls', - 'commands.Workflow_New.label': 'New Blank Workflow' +const i18n = createI18n({ + legacy: false, + locale: 'en', + messages: { + en: { + shortcuts: { + subcategories: { + workflow: 'Workflow', + node: 'Node', + queue: 'Queue', + view: 'View', + panelControls: 'Panel Controls' + } + }, + commands: { + Workflow_New: { label: 'New Blank Workflow' }, + Node_Add: { label: 'Add Node' }, + Queue_Clear: { label: 'Clear Queue' }, + Special_Keys: { label: 'Special Keys' } + } + } } - return translations[key] || key }) -vi.mock('vue-i18n', () => ({ - useI18n: () => ({ - t: mockT - }) -})) - describe('ShortcutsList', () => { const mockCommands: ComfyCommandImpl[] = [ { @@ -68,6 +74,9 @@ describe('ShortcutsList', () => { render(ShortcutsList, { props: { subcategories: mockSubcategories + }, + global: { + plugins: [i18n] } }) @@ -81,6 +90,9 @@ describe('ShortcutsList', () => { const { container } = render(ShortcutsList, { props: { subcategories: mockSubcategories + }, + global: { + plugins: [i18n] } }) @@ -109,6 +121,9 @@ describe('ShortcutsList', () => { ...mockSubcategories, other: [commandsWithoutKeybinding[3]] } + }, + global: { + plugins: [i18n] } }) @@ -132,6 +147,9 @@ describe('ShortcutsList', () => { subcategories: { special: [specialKeyCommand] } + }, + global: { + plugins: [i18n] } }) @@ -149,6 +167,9 @@ describe('ShortcutsList', () => { subcategories: { unknown: [mockCommands[0]] } + }, + global: { + plugins: [i18n] } }) diff --git a/src/components/bottomPanel/tabs/terminal/BaseTerminal.test.ts b/src/components/bottomPanel/tabs/terminal/BaseTerminal.test.ts index d5353fa17f3..67f619f9ac2 100644 --- a/src/components/bottomPanel/tabs/terminal/BaseTerminal.test.ts +++ b/src/components/bottomPanel/tabs/terminal/BaseTerminal.test.ts @@ -10,7 +10,7 @@ import { createI18n } from 'vue-i18n' import BaseTerminal from '@/components/bottomPanel/tabs/terminal/BaseTerminal.vue' // Mock xterm and related modules -vi.mock('@xterm/xterm', () => ({ +vi.mock(import('@xterm/xterm'), () => ({ Terminal: vi.fn().mockImplementation(() => ({ open: vi.fn(), dispose: vi.fn(), @@ -29,7 +29,7 @@ vi.mock('@xterm/xterm', () => ({ IDisposable: vi.fn() })) -vi.mock('@xterm/addon-fit', () => ({ +vi.mock(import('@xterm/addon-fit'), () => ({ FitAddon: vi.fn().mockImplementation(() => ({ fit: vi.fn(), proposeDimensions: vi.fn(() => ({ rows: 24, cols: 80 })) @@ -48,20 +48,20 @@ const mockTerminal = { clearSelection: vi.fn() } -vi.mock('@/composables/bottomPanelTabs/useTerminal', () => ({ +vi.mock(import('@/composables/bottomPanelTabs/useTerminal'), () => ({ useTerminal: vi.fn(() => ({ terminal: mockTerminal, useAutoSize: vi.fn(() => ({ resize: vi.fn() })) })) })) -vi.mock('@/utils/envUtil', () => ({ +vi.mock(import('@/utils/envUtil'), () => ({ electronAPI: vi.fn(() => null) })) const mockData = vi.hoisted(() => ({ isDesktop: false })) -vi.mock('@/platform/distribution/types', () => ({ +vi.mock(import('@/platform/distribution/types'), () => ({ get isDesktop() { return mockData.isDesktop } diff --git a/src/components/bottomPanel/tabs/terminal/LogsTerminal.test.ts b/src/components/bottomPanel/tabs/terminal/LogsTerminal.test.ts index 924a7466c53..1cfcde07096 100644 --- a/src/components/bottomPanel/tabs/terminal/LogsTerminal.test.ts +++ b/src/components/bottomPanel/tabs/terminal/LogsTerminal.test.ts @@ -15,7 +15,7 @@ const apiMock = vi.hoisted( })() ) -vi.mock('@/scripts/api', () => ({ api: apiMock })) +vi.mock(import('@/scripts/api'), () => ({ api: apiMock })) const terminalMock = vi.hoisted(() => ({ open: vi.fn(), @@ -30,28 +30,31 @@ const terminalMock = vi.hoisted(() => ({ clearSelection: vi.fn() })) -vi.mock('@/composables/bottomPanelTabs/useTerminal', () => ({ +vi.mock(import('@/composables/bottomPanelTabs/useTerminal'), () => ({ useTerminal: vi.fn(() => ({ terminal: terminalMock, useAutoSize: vi.fn(() => ({ resize: vi.fn() })) })) })) -vi.mock('@/components/bottomPanel/tabs/terminal/BaseTerminal.vue', async () => { - const { defineComponent, ref } = await import('vue') - const { useTerminal } = - await import('@/composables/bottomPanelTabs/useTerminal') - return { - default: defineComponent({ - emits: ['created'], - setup(_, { emit }) { - const root = ref(undefined) - emit('created', useTerminal(root), root) - return () => null - } - }) +vi.mock( + import('@/components/bottomPanel/tabs/terminal/BaseTerminal.vue'), + async () => { + const { defineComponent, ref } = await import('vue') + const { useTerminal } = + await import('@/composables/bottomPanelTabs/useTerminal') + return { + default: defineComponent({ + emits: ['created'], + setup(_, { emit }) { + const root = ref(undefined) + emit('created', useTerminal(root), root) + return () => null + } + }) + } } -}) +) const i18n = createI18n({ legacy: false, diff --git a/src/components/boundingBoxes/WidgetBoundingBoxes.test.ts b/src/components/boundingBoxes/WidgetBoundingBoxes.test.ts index 3907061daac..1562937fca4 100644 --- a/src/components/boundingBoxes/WidgetBoundingBoxes.test.ts +++ b/src/components/boundingBoxes/WidgetBoundingBoxes.test.ts @@ -14,7 +14,7 @@ const { appState } = vi.hoisted(() => { return { appState } }) -vi.mock('@/scripts/app', () => ({ +vi.mock(import('@/scripts/app'), () => ({ app: { canvas: { graph: { getNodeById: () => appState.node } }, nodeOutputs: {}, diff --git a/src/components/breadcrumb/SubgraphBreadcrumb.test.ts b/src/components/breadcrumb/SubgraphBreadcrumb.test.ts index 4056c8e6184..13d5f7b2d1d 100644 --- a/src/components/breadcrumb/SubgraphBreadcrumb.test.ts +++ b/src/components/breadcrumb/SubgraphBreadcrumb.test.ts @@ -6,23 +6,30 @@ import SubgraphBreadcrumb from './SubgraphBreadcrumb.vue' const canvasState = vi.hoisted(() => ({ linearMode: false })) -vi.mock('@/platform/workflow/management/stores/workflowStore', () => ({ - useWorkflowStore: () => ({ activeWorkflow: { filename: 'workflow.json' } }) -})) +vi.mock( + import('@/platform/workflow/management/stores/workflowStore'), + () => ({ + useWorkflowStore: () => ({ activeWorkflow: { filename: 'workflow.json' } }) + }) +) -vi.mock('@/stores/subgraphNavigationStore', () => ({ +vi.mock(import('@/stores/subgraphNavigationStore'), () => ({ useSubgraphNavigationStore: () => ({ navigationStack: [] }) })) -vi.mock('@/stores/subgraphStore', () => ({ +vi.mock(import('@/stores/subgraphStore'), () => ({ useSubgraphStore: () => ({ isSubgraphBlueprint: () => false }) })) -vi.mock('@/renderer/core/canvas/canvasStore', () => ({ - useCanvasStore: () => ({ linearMode: canvasState.linearMode }) -})) +vi.mock( + import('@/renderer/core/canvas/canvasStore'), + + () => ({ + useCanvasStore: () => ({ linearMode: canvasState.linearMode }) + }) +) -vi.mock('@/composables/element/useOverflowObserver', () => ({ +vi.mock(import('@/composables/element/useOverflowObserver'), () => ({ useOverflowObserver: () => ({ dispose: vi.fn(), checkOverflow: vi.fn(), diff --git a/src/components/builder/BuilderFooterToolbar.test.ts b/src/components/builder/BuilderFooterToolbar.test.ts index 83c044512e5..de62b121c1d 100644 --- a/src/components/builder/BuilderFooterToolbar.test.ts +++ b/src/components/builder/BuilderFooterToolbar.test.ts @@ -17,7 +17,7 @@ const mockState = { mode: 'builder:inputs' as AppMode } -vi.mock('@/composables/useAppMode', () => ({ +vi.mock(import('@/composables/useAppMode'), () => ({ useAppMode: () => ({ mode: computed(() => mockState.mode), isBuilderMode: ref(true), @@ -27,7 +27,7 @@ vi.mock('@/composables/useAppMode', () => ({ const mockHasOutputs = ref(true) -vi.mock('@/stores/appModeStore', () => ({ +vi.mock(import('@/stores/appModeStore'), () => ({ useAppModeStore: () => ({ exitBuilder: mockExitBuilder, hasOutputs: mockHasOutputs, @@ -35,7 +35,7 @@ vi.mock('@/stores/appModeStore', () => ({ }) })) -vi.mock('@/stores/dialogStore', () => ({ +vi.mock(import('@/stores/dialogStore'), () => ({ useDialogStore: () => ({ dialogStack: [] }) @@ -51,23 +51,26 @@ const mockActiveWorkflow = ref<{ initialMode: 'app' }) -vi.mock('@/platform/workflow/management/stores/workflowStore', () => ({ - useWorkflowStore: () => ({ - get activeWorkflow() { - return mockActiveWorkflow.value - } +vi.mock( + import('@/platform/workflow/management/stores/workflowStore'), + () => ({ + useWorkflowStore: () => ({ + get activeWorkflow() { + return mockActiveWorkflow.value + } + }) }) -})) +) -vi.mock('@/scripts/app', () => ({ +vi.mock(import('@/scripts/app'), () => ({ app: { rootGraph: { extra: {} } } })) -vi.mock('@/platform/telemetry', () => ({ +vi.mock(import('@/platform/telemetry'), () => ({ useTelemetry: () => null })) -vi.mock('./useBuilderSave', () => ({ +vi.mock(import('./useBuilderSave'), () => ({ useBuilderSave: () => ({ save: mockSave, saveAs: mockSaveAs, diff --git a/src/components/builder/builderViewOptions.test.ts b/src/components/builder/builderViewOptions.test.ts index 785d5d1601c..eacae7e5c53 100644 --- a/src/components/builder/builderViewOptions.test.ts +++ b/src/components/builder/builderViewOptions.test.ts @@ -6,13 +6,13 @@ import type { setWorkflowDefaultView as SetWorkflowDefaultViewFn } from './build const mockTrackDefaultViewSet = vi.hoisted(() => vi.fn()) -vi.mock('@/i18n', () => ({ t: (key: string) => key })) +vi.mock(import('@/i18n'), () => ({ t: (key: string) => key })) -vi.mock('@/platform/telemetry', () => ({ +vi.mock(import('@/platform/telemetry'), () => ({ useTelemetry: () => ({ trackDefaultViewSet: mockTrackDefaultViewSet }) })) -vi.mock('@/scripts/app', () => { +vi.mock(import('@/scripts/app'), () => { const rootGraph = { extra: {} } return { app: { rootGraph, rootGraphOrUndefined: rootGraph } } }) diff --git a/src/components/builder/useBuilderSave.test.ts b/src/components/builder/useBuilderSave.test.ts index 7efdfea22fa..3c90e0b0a7b 100644 --- a/src/components/builder/useBuilderSave.test.ts +++ b/src/components/builder/useBuilderSave.test.ts @@ -21,60 +21,66 @@ const mockActiveWorkflow = ref<{ initialMode?: string | null } | null>(null) -vi.mock('@/composables/useAppMode', () => ({ +vi.mock(import('@/composables/useAppMode'), () => ({ useAppMode: () => ({ setMode: mockSetMode }) })) -vi.mock('@/composables/useErrorHandling', () => ({ +vi.mock(import('@/composables/useErrorHandling'), () => ({ useErrorHandling: () => ({ toastErrorHandler: mockToastErrorHandler }) })) -vi.mock('@/platform/telemetry', () => ({ +vi.mock(import('@/platform/telemetry'), () => ({ useTelemetry: () => ({ trackEnterLinear: mockTrackEnterLinear, trackDefaultViewSet: mockTrackDefaultViewSet }) })) -vi.mock('@/platform/workflow/core/services/workflowService', () => ({ - useWorkflowService: () => ({ - saveWorkflow: mockSaveWorkflow, - saveWorkflowAs: mockSaveWorkflowAs +vi.mock( + import('@/platform/workflow/core/services/workflowService'), + () => ({ + useWorkflowService: () => ({ + saveWorkflow: mockSaveWorkflow, + saveWorkflowAs: mockSaveWorkflowAs + }) }) -})) +) -vi.mock('@/platform/workflow/management/stores/workflowStore', () => ({ - useWorkflowStore: () => ({ - get activeWorkflow() { - return mockActiveWorkflow.value - } +vi.mock( + import('@/platform/workflow/management/stores/workflowStore'), + () => ({ + useWorkflowStore: () => ({ + get activeWorkflow() { + return mockActiveWorkflow.value + } + }) }) -})) +) -vi.mock('@/services/dialogService', () => ({ +vi.mock(import('@/services/dialogService'), () => ({ useDialogService: () => ({ showLayoutDialog: mockShowLayoutDialog }) })) -vi.mock('@/stores/appModeStore', () => ({ +vi.mock(import('@/stores/appModeStore'), () => ({ useAppModeStore: () => ({ exitBuilder: mockExitBuilder }) })) -vi.mock('@/stores/dialogStore', () => ({ +vi.mock(import('@/stores/dialogStore'), () => ({ useDialogStore: () => ({ closeDialog: mockCloseDialog }) })) -vi.mock('@/components/dialog/confirm/confirmDialog', () => ({ +vi.mock(import('@/components/dialog/confirm/confirmDialog'), () => ({ showConfirmDialog: mockShowConfirmDialog })) -vi.mock('@/i18n', () => ({ +vi.mock(import('@/i18n'), () => ({ t: (key: string, params?: Record) => { if (params) return `${key}:${JSON.stringify(params)}` return key } })) -vi.mock('./BuilderSaveDialogContent.vue', () => ({ +vi.mock(import('./BuilderSaveDialogContent.vue'), () => ({ default: { template: '
' } })) diff --git a/src/components/builder/useResolvedSelectedInputs.test.ts b/src/components/builder/useResolvedSelectedInputs.test.ts index 6f63e6ea132..976de960d98 100644 --- a/src/components/builder/useResolvedSelectedInputs.test.ts +++ b/src/components/builder/useResolvedSelectedInputs.test.ts @@ -11,7 +11,7 @@ import { widgetId } from '@/types/widgetId' import { useResolvedSelectedInputs } from './useResolvedSelectedInputs' -vi.mock('@/scripts/app', () => ({ +vi.mock(import('@/scripts/app'), () => ({ app: { rootGraph: { id: '11111111-1111-4111-8111-111111111111', diff --git a/src/components/cameraInfo/CameraInfo.test.ts b/src/components/cameraInfo/CameraInfo.test.ts index 7fbfa2d2d73..a4b68dd3111 100644 --- a/src/components/cameraInfo/CameraInfo.test.ts +++ b/src/components/cameraInfo/CameraInfo.test.ts @@ -34,7 +34,7 @@ const holder = vi.hoisted(() => ({ api: null as ApiMocks | null })) -vi.mock('@/composables/useCameraInfo', async () => { +vi.mock(import('@/composables/useCameraInfo'), async () => { const { ref } = await import('vue') const modeRef = ref('orbit') const api = { @@ -51,7 +51,7 @@ vi.mock('@/composables/useCameraInfo', async () => { return { useCameraInfo: () => ({ ...api, mode: modeRef }) } }) -vi.mock('@vueuse/core', () => ({ +vi.mock(import('@vueuse/core'), () => ({ createSharedComposable: (composable: () => unknown) => composable, useDocumentVisibility: () => ref('visible'), useElementSize: () => ({ width: ref(600), height: ref(400) }), diff --git a/src/components/common/CustomizationDialog.test.ts b/src/components/common/CustomizationDialog.test.ts index 75c2c55c044..3cacf606cf8 100644 --- a/src/components/common/CustomizationDialog.test.ts +++ b/src/components/common/CustomizationDialog.test.ts @@ -8,7 +8,7 @@ import CustomizationDialog from './CustomizationDialog.vue' const DEFAULT_ICON = 'pi-bookmark-fill' const DEFAULT_COLOR = '#a1a1aa' -vi.mock('@/stores/nodeBookmarkStore', () => ({ +vi.mock(import('@/stores/nodeBookmarkStore'), () => ({ useNodeBookmarkStore: () => ({ defaultBookmarkIcon: DEFAULT_ICON, defaultBookmarkColor: DEFAULT_COLOR, @@ -16,48 +16,55 @@ vi.mock('@/stores/nodeBookmarkStore', () => ({ }) })) -vi.mock('primevue/selectbutton', () => ({ - default: { - name: 'SelectButton', - template: '
', - props: ['modelValue', 'options'] - } -})) +vi.mock( + import('primevue/selectbutton'), // eslint-disable-line primevue-removal/no-imports + + () => ({ + default: { + name: 'SelectButton', + template: '
', + props: ['modelValue', 'options'] + } + }) +) -vi.mock('@/components/ui/dialog/Dialog.vue', () => ({ +vi.mock(import('@/components/ui/dialog/Dialog.vue'), () => ({ default: { name: 'Dialog', template: '
' } })) -vi.mock('@/components/ui/dialog/DialogPortal.vue', () => ({ +vi.mock(import('@/components/ui/dialog/DialogPortal.vue'), () => ({ default: { name: 'DialogPortal', template: '
' } })) -vi.mock('@/components/ui/dialog/DialogOverlay.vue', () => ({ +vi.mock(import('@/components/ui/dialog/DialogOverlay.vue'), () => ({ default: { name: 'DialogOverlay', template: '
' } })) -vi.mock('@/components/ui/dialog/DialogContent.vue', () => ({ +vi.mock(import('@/components/ui/dialog/DialogContent.vue'), () => ({ default: { name: 'DialogContent', template: '
' } })) -vi.mock('@/components/ui/dialog/DialogHeader.vue', () => ({ +vi.mock(import('@/components/ui/dialog/DialogHeader.vue'), () => ({ default: { name: 'DialogHeader', template: '
' } })) -vi.mock('@/components/ui/dialog/DialogFooter.vue', () => ({ +vi.mock(import('@/components/ui/dialog/DialogFooter.vue'), () => ({ default: { name: 'DialogFooter', template: '
' } })) -vi.mock('@/components/ui/dialog/DialogTitle.vue', () => ({ +vi.mock(import('@/components/ui/dialog/DialogTitle.vue'), () => ({ default: { name: 'DialogTitle', template: '
' } })) -vi.mock('@/components/ui/dialog/DialogClose.vue', () => ({ +vi.mock(import('@/components/ui/dialog/DialogClose.vue'), () => ({ default: { name: 'DialogClose', template: '`, diff --git a/src/components/common/SystemStatsPanel.test.ts b/src/components/common/SystemStatsPanel.test.ts index 3bd86d7de77..770899a97a0 100644 --- a/src/components/common/SystemStatsPanel.test.ts +++ b/src/components/common/SystemStatsPanel.test.ts @@ -9,7 +9,7 @@ import type { SystemStats } from '@/schemas/apiSchema' import SystemStatsPanel from './SystemStatsPanel.vue' const copyToClipboard = vi.fn() -vi.mock('@/composables/useCopyToClipboard', () => ({ +vi.mock(import('@/composables/useCopyToClipboard'), () => ({ useCopyToClipboard: () => ({ copyToClipboard }) })) diff --git a/src/components/common/TextTickerMultiLine.test.ts b/src/components/common/TextTickerMultiLine.test.ts index 7f45caf0bf7..65c3b6d3f8a 100644 --- a/src/components/common/TextTickerMultiLine.test.ts +++ b/src/components/common/TextTickerMultiLine.test.ts @@ -8,7 +8,7 @@ const hoisted = vi.hoisted(() => ({ widths: [] as { value: number }[] })) -vi.mock('@vueuse/core', () => ({ +vi.mock(import('@vueuse/core'), () => ({ useElementSize: () => { const width = ref(0) hoisted.widths.push(width) diff --git a/src/components/common/TreeExplorerV2Node.test.ts b/src/components/common/TreeExplorerV2Node.test.ts index e02b543d31b..64d1fabb360 100644 --- a/src/components/common/TreeExplorerV2Node.test.ts +++ b/src/components/common/TreeExplorerV2Node.test.ts @@ -17,13 +17,13 @@ const i18n = createI18n({ messages: { en: { g: { delete: 'Delete' } } } }) -vi.mock('@/platform/settings/settingStore', () => ({ +vi.mock(import('@/platform/settings/settingStore'), () => ({ useSettingStore: () => ({ get: vi.fn().mockReturnValue('left') }) })) -vi.mock('@/stores/nodeBookmarkStore', () => ({ +vi.mock(import('@/stores/nodeBookmarkStore'), () => ({ useNodeBookmarkStore: () => ({ isBookmarked: vi.fn().mockReturnValue(false), toggleBookmark: vi.fn() @@ -33,7 +33,7 @@ vi.mock('@/stores/nodeBookmarkStore', () => ({ const mockDeleteBlueprint = vi.fn() const mockIsUserBlueprint = vi.fn().mockReturnValue(false) -vi.mock('@/stores/subgraphStore', () => ({ +vi.mock(import('@/stores/subgraphStore'), () => ({ useSubgraphStore: () => ({ isUserBlueprint: mockIsUserBlueprint, deleteBlueprint: mockDeleteBlueprint, @@ -41,14 +41,14 @@ vi.mock('@/stores/subgraphStore', () => ({ }) })) -vi.mock('@/components/node/NodePreviewCard.vue', () => ({ +vi.mock(import('@/components/node/NodePreviewCard.vue'), () => ({ default: { template: '
' } })) const mockStartDrag = vi.fn() const mockHandleNativeDrop = vi.fn() -vi.mock('@/composables/node/useNodeDragToCanvas', () => ({ +vi.mock(import('@/composables/node/useNodeDragToCanvas'), () => ({ useNodeDragToCanvas: () => ({ startDrag: mockStartDrag, handleNativeDrop: mockHandleNativeDrop diff --git a/src/components/common/UserCredit.test.ts b/src/components/common/UserCredit.test.ts index 4681e286a71..99baeaa0f0c 100644 --- a/src/components/common/UserCredit.test.ts +++ b/src/components/common/UserCredit.test.ts @@ -1,17 +1,18 @@ import { render, screen } from '@testing-library/vue' import { beforeEach, describe, expect, it, vi } from 'vitest' +import { createPinia } from 'pinia' import { createI18n } from 'vue-i18n' import enMessages from '@/locales/en/main.json' with { type: 'json' } import UserCredit from './UserCredit.vue' -vi.mock('firebase/app', () => ({ +vi.mock(import('firebase/app'), () => ({ initializeApp: vi.fn(), getApp: vi.fn() })) -vi.mock('firebase/auth', () => ({ +vi.mock(import('firebase/auth'), () => ({ getAuth: vi.fn(), setPersistence: vi.fn(), browserLocalPersistence: {}, @@ -20,8 +21,6 @@ vi.mock('firebase/auth', () => ({ signOut: vi.fn() })) -vi.mock('pinia') - const mockBalance = vi.hoisted(() => ({ value: { amount_micros: 100_000, @@ -32,7 +31,7 @@ const mockBalance = vi.hoisted(() => ({ const mockIsFetchingBalance = vi.hoisted(() => ({ value: false })) -vi.mock('@/stores/authStore', () => ({ +vi.mock(import('@/stores/authStore'), () => ({ useAuthStore: vi.fn(() => ({ balance: mockBalance.value, isFetchingBalance: mockIsFetchingBalance.value @@ -59,7 +58,7 @@ describe('UserCredit', () => { return render(UserCredit, { props, global: { - plugins: [i18n], + plugins: [i18n, createPinia()], stubs: { Skeleton: { template: '
' }, Tag: true diff --git a/src/components/common/VirtualGrid.test.ts b/src/components/common/VirtualGrid.test.ts index a946966b24c..f0d6bde7e3f 100644 --- a/src/components/common/VirtualGrid.test.ts +++ b/src/components/common/VirtualGrid.test.ts @@ -11,7 +11,7 @@ let mockedWidth: Ref let mockedHeight: Ref let mockedScrollY: Ref -vi.mock('@vueuse/core', async () => { +vi.mock(import('@vueuse/core'), async () => { const actual = await vi.importActual>('@vueuse/core') return { ...actual, diff --git a/src/components/common/WorkflowActionsDropdown.test.ts b/src/components/common/WorkflowActionsDropdown.test.ts index 0787f5456b7..30432a68bb1 100644 --- a/src/components/common/WorkflowActionsDropdown.test.ts +++ b/src/components/common/WorkflowActionsDropdown.test.ts @@ -19,7 +19,7 @@ const viewState = vi.hoisted(() => ({ displayViewMode: 'graph' as ViewMode })) -vi.mock('@/stores/appModeStore', async () => { +vi.mock(import('@/stores/appModeStore'), async () => { const { computed, reactive } = await import('vue') return { useAppModeStore: () => @@ -30,26 +30,26 @@ vi.mock('@/stores/appModeStore', async () => { } }) -vi.mock('@/stores/commandStore', () => ({ +vi.mock(import('@/stores/commandStore'), () => ({ useCommandStore: () => ({ execute: spies.execute, commands: [] }) })) -vi.mock('@/platform/keybindings/keybindingStore', () => ({ +vi.mock(import('@/platform/keybindings/keybindingStore'), () => ({ useKeybindingStore: () => ({ getKeybindingByCommandId: () => ({ combo: { toString: () => 'Ctrl+L' } }) }) })) -vi.mock('@/platform/telemetry', () => ({ +vi.mock(import('@/platform/telemetry'), () => ({ useTelemetry: () => ({ trackUiButtonClicked: spies.trackUiButtonClicked }) })) -vi.mock('@/composables/useWorkflowActionsMenu', async () => { +vi.mock(import('@/composables/useWorkflowActionsMenu'), async () => { const { ref } = await import('vue') return { useWorkflowActionsMenu: () => ({ menuItems: ref([]) }) } }) -vi.mock('@/composables/useNewMenuItemIndicator', async () => { +vi.mock(import('@/composables/useNewMenuItemIndicator'), async () => { const { ref } = await import('vue') return { useNewMenuItemIndicator: () => ({ diff --git a/src/components/curve/WidgetCurve.test.ts b/src/components/curve/WidgetCurve.test.ts index b283c8be793..6a8f79ce553 100644 --- a/src/components/curve/WidgetCurve.test.ts +++ b/src/components/curve/WidgetCurve.test.ts @@ -25,7 +25,7 @@ const upstreamHolder = vi.hoisted(() => ({ ref: null as { value: unknown } | null })) -vi.mock('@/composables/useUpstreamValue', async () => { +vi.mock(import('@/composables/useUpstreamValue'), async () => { const { ref } = await import('vue') return { useUpstreamValue: () => { @@ -40,7 +40,7 @@ const outputsHolder = vi.hoisted(() => ({ nodeOutputs: {} as Record })) -vi.mock('@/stores/nodeOutputStore', () => ({ +vi.mock(import('@/stores/nodeOutputStore'), () => ({ useNodeOutputStore: () => outputsHolder })) diff --git a/src/components/dialog/GlobalDialog.test.ts b/src/components/dialog/GlobalDialog.test.ts index 4c7bfc64999..bcfd41bce93 100644 --- a/src/components/dialog/GlobalDialog.test.ts +++ b/src/components/dialog/GlobalDialog.test.ts @@ -18,8 +18,8 @@ import SetMemberCreditLimitDialogContent from '@/platform/workspace/components/d import SubscriptionRequiredDialogContentUnified from '@/platform/workspace/components/SubscriptionRequiredDialogContentUnified.vue' import { useDialogStore } from '@/stores/dialogStore' -vi.mock( - '@/platform/workspace/composables/useSubscriptionCheckout', +vi.mock( + import('@/platform/workspace/composables/useSubscriptionCheckout'), async () => { const { computed, ref } = await import('vue') diff --git a/src/components/dialog/confirm/confirmDialog.test.ts b/src/components/dialog/confirm/confirmDialog.test.ts index f02ad461c7f..290a8287256 100644 --- a/src/components/dialog/confirm/confirmDialog.test.ts +++ b/src/components/dialog/confirm/confirmDialog.test.ts @@ -8,7 +8,7 @@ import { describe, expect, it, vi } from 'vitest' const showDialog = vi.hoisted(() => vi.fn()) -vi.mock('@/stores/dialogStore', () => ({ +vi.mock(import('@/stores/dialogStore'), () => ({ useDialogStore: () => ({ showDialog }) })) diff --git a/src/components/dialog/content/SignInContent.test.ts b/src/components/dialog/content/SignInContent.test.ts index 42a4e837a12..6600defa384 100644 --- a/src/components/dialog/content/SignInContent.test.ts +++ b/src/components/dialog/content/SignInContent.test.ts @@ -5,7 +5,7 @@ import { createI18n } from 'vue-i18n' import SignInContent from '@/components/dialog/content/SignInContent.vue' -vi.mock('@/composables/auth/useAuthActions', () => ({ +vi.mock(import('@/composables/auth/useAuthActions'), () => ({ useAuthActions: () => ({ signInWithGoogle: vi.fn(), signInWithGithub: vi.fn(), @@ -15,12 +15,14 @@ vi.mock('@/composables/auth/useAuthActions', () => ({ }) })) -vi.mock('@/base/webviewDetection', () => ({ isEmbeddedWebView: () => false })) -vi.mock('@/utils/hostWhitelist', () => ({ +vi.mock(import('@/base/webviewDetection'), () => ({ + isEmbeddedWebView: () => false +})) +vi.mock(import('@/utils/hostWhitelist'), () => ({ isHostWhitelisted: () => true, normalizeHost: (host: string) => host })) -vi.mock('@/platform/remoteConfig/remoteConfig', () => ({ +vi.mock(import('@/platform/remoteConfig/remoteConfig'), () => ({ remoteConfig: ref({}), configValueOrDefault: (_config: unknown, _key: string, fallback: string) => fallback @@ -45,7 +47,7 @@ const inChina = vi.hoisted(() => ({ this.pending = Promise.reject(error) } })) -vi.mock('@/utils/networkUtil', () => ({ +vi.mock(import('@/utils/networkUtil'), () => ({ isInChina: () => inChina.pending ?? Promise.resolve(inChina.value) })) diff --git a/src/components/dialog/content/TopUpCreditsDialogContentLegacy.test.ts b/src/components/dialog/content/TopUpCreditsDialogContentLegacy.test.ts index 5dfa1a89e09..1190f3a31b1 100644 --- a/src/components/dialog/content/TopUpCreditsDialogContentLegacy.test.ts +++ b/src/components/dialog/content/TopUpCreditsDialogContentLegacy.test.ts @@ -16,13 +16,13 @@ const mockTrackBillingEvent = vi.fn() const mockIsSubscriptionEnabled = vi.fn(() => true) const mockShouldUseWorkspaceBilling = vi.hoisted(() => ({ value: false })) -vi.mock('@/composables/auth/useAuthActions', () => ({ +vi.mock(import('@/composables/auth/useAuthActions'), () => ({ useAuthActions: () => ({ purchaseCreditsDirect: (amount: number) => mockPurchaseCreditsDirect(amount) }) })) -vi.mock('@/composables/billing/useBillingRouting', () => ({ +vi.mock(import('@/composables/billing/useBillingRouting'), () => ({ useBillingRouting: () => ({ shouldUseWorkspaceBilling: { get value() { @@ -32,21 +32,27 @@ vi.mock('@/composables/billing/useBillingRouting', () => ({ }) })) -vi.mock('@/platform/cloud/subscription/composables/useSubscription', () => ({ - useSubscription: () => ({ - isSubscriptionEnabled: mockIsSubscriptionEnabled +vi.mock( + import('@/platform/cloud/subscription/composables/useSubscription'), + () => ({ + useSubscription: () => ({ + isSubscriptionEnabled: mockIsSubscriptionEnabled + }) }) -})) +) -vi.mock('@/platform/settings/composables/useSettingsDialog', () => ({ - useSettingsDialog: () => ({ show: mockShowSettings }) -})) +vi.mock( + import('@/platform/settings/composables/useSettingsDialog'), + () => ({ + useSettingsDialog: () => ({ show: mockShowSettings }) + }) +) -vi.mock('@/stores/dialogStore', () => ({ +vi.mock(import('@/stores/dialogStore'), () => ({ useDialogStore: () => ({ closeDialog: mockCloseDialog }) })) -vi.mock('@/platform/telemetry', () => ({ +vi.mock(import('@/platform/telemetry'), () => ({ useTelemetry: () => ({ trackApiCreditTopupButtonPurchaseClicked: mockTrackTopUpPurchase, trackBillingEvent: mockTrackBillingEvent @@ -54,22 +60,26 @@ vi.mock('@/platform/telemetry', () => ({ })) const mockClearPendingTopup = vi.hoisted(() => vi.fn()) -vi.mock('@/composables/billing/usePendingTopup', () => ({ +vi.mock(import('@/composables/billing/usePendingTopup'), () => ({ usePendingTopup: () => ({ clearPendingTopup: mockClearPendingTopup }) })) -vi.mock('@/composables/useExternalLink', () => ({ +vi.mock(import('@/composables/useExternalLink'), () => ({ useExternalLink: () => ({ buildDocsUrl: () => 'https://docs.comfy.org', docsPaths: { partnerNodesPricing: '' } }) })) -vi.mock('primevue/usetoast', () => ({ - useToast: () => ({ add: mockToastAdd }) -})) +vi.mock( + import('primevue/usetoast'), // eslint-disable-line primevue-removal/no-imports + + () => ({ + useToast: () => ({ add: mockToastAdd }) + }) +) -vi.mock('@/base/credits/comfyCredits', () => ({ +vi.mock(import('@/base/credits/comfyCredits'), () => ({ creditsToUsd: (credits: number) => credits, usdToCredits: (usd: number) => usd })) diff --git a/src/components/dialog/content/setting/CreditsPanel.test.ts b/src/components/dialog/content/setting/CreditsPanel.test.ts index 69e295a1596..0e516f46d9c 100644 --- a/src/components/dialog/content/setting/CreditsPanel.test.ts +++ b/src/components/dialog/content/setting/CreditsPanel.test.ts @@ -12,20 +12,23 @@ const billingMocks = vi.hoisted(() => ({ balance: { value: null as BalanceInfo | null }, manageSubscription: vi.fn() })) -vi.mock('@/composables/billing/useBillingContext', async () => { - const { ref } = await import('vue') - const balance = ref(null) - Object.defineProperty(billingMocks, 'balance', { get: () => balance }) - return { - useBillingContext: () => ({ - balance, - manageSubscription: billingMocks.manageSubscription - }) +vi.mock( + import('@/composables/billing/useBillingContext'), + async () => { + const { ref } = await import('vue') + const balance = ref(null) + Object.defineProperty(billingMocks, 'balance', { get: () => balance }) + return { + useBillingContext: () => ({ + balance, + manageSubscription: billingMocks.manageSubscription + }) + } } -}) +) const refreshActivity = vi.hoisted(() => vi.fn()) -vi.mock('./UsageLogsTable.vue', async () => { +vi.mock(import('./UsageLogsTable.vue'), async () => { const { defineComponent, h } = await import('vue') return { default: defineComponent({ @@ -37,19 +40,22 @@ vi.mock('./UsageLogsTable.vue', async () => { } }) -vi.mock('@/platform/cloud/subscription/components/CreditsTile.vue', () => ({ - default: defineComponent({ setup: () => () => h('div') }) -})) +vi.mock( + import('@/platform/cloud/subscription/components/CreditsTile.vue'), + () => ({ + default: defineComponent({ setup: () => () => h('div') }) + }) +) -vi.mock('@/platform/telemetry', () => ({ +vi.mock(import('@/platform/telemetry'), () => ({ useTelemetry: () => ({ trackHelpResourceClicked: vi.fn() }) })) -vi.mock('@/stores/commandStore', () => ({ +vi.mock(import('@/stores/commandStore'), () => ({ useCommandStore: () => ({ execute: vi.fn() }) })) -vi.mock('@/composables/useExternalLink', () => ({ +vi.mock(import('@/composables/useExternalLink'), () => ({ useExternalLink: () => ({ buildDocsUrl: () => 'https://docs.comfy.org', docsPaths: { partnerNodesPricing: '/partner-nodes' } diff --git a/src/components/dialog/content/setting/SettingItem.test.ts b/src/components/dialog/content/setting/SettingItem.test.ts index 2551090dca6..d069830ecd1 100644 --- a/src/components/dialog/content/setting/SettingItem.test.ts +++ b/src/components/dialog/content/setting/SettingItem.test.ts @@ -16,7 +16,7 @@ const i18n = createI18n({ locale: 'en' }) -vi.mock('@/utils/formatUtil', () => ({ +vi.mock(import('@/utils/formatUtil'), () => ({ normalizeI18nKey: vi.fn() })) diff --git a/src/components/dialog/content/setting/UsageLogsTable.test.ts b/src/components/dialog/content/setting/UsageLogsTable.test.ts index f3c8d0a03b6..8f10fe9653c 100644 --- a/src/components/dialog/content/setting/UsageLogsTable.test.ts +++ b/src/components/dialog/content/setting/UsageLogsTable.test.ts @@ -24,7 +24,7 @@ const mockCustomerEventsService = vi.hoisted(() => ({ isLoading: { value: false } })) -vi.mock('@/services/customerEventsService', () => ({ +vi.mock(import('@/services/customerEventsService'), () => ({ useCustomerEventsService: () => mockCustomerEventsService, EventType: { CREDIT_ADDED: 'credit_added', @@ -37,38 +37,41 @@ vi.mock('@/services/customerEventsService', () => ({ const mockTelemetry = vi.hoisted(() => ({ trackApiCreditTopupSucceeded: vi.fn() })) -vi.mock('@/platform/telemetry', () => ({ +vi.mock(import('@/platform/telemetry'), () => ({ useTelemetry: () => mockTelemetry })) const mockPendingTopup = vi.hoisted(() => ({ isPendingTopupCompleted: vi.fn().mockReturnValue(true) })) -vi.mock('@/composables/billing/usePendingTopup', () => ({ +vi.mock(import('@/composables/billing/usePendingTopup'), () => ({ usePendingTopup: () => mockPendingTopup })) const mockBillingRouting = vi.hoisted(() => ({ shouldUseWorkspaceBilling: false })) -vi.mock('@/composables/billing/useBillingRouting', async () => { - const { ref } = await import('vue') - const shouldUseWorkspaceBilling = ref(false) - Object.defineProperty(mockBillingRouting, 'shouldUseWorkspaceBilling', { - get: () => shouldUseWorkspaceBilling.value, - set: (value: boolean) => { - shouldUseWorkspaceBilling.value = value +vi.mock( + import('@/composables/billing/useBillingRouting'), + async () => { + const { ref } = await import('vue') + const shouldUseWorkspaceBilling = ref(false) + Object.defineProperty(mockBillingRouting, 'shouldUseWorkspaceBilling', { + get: () => shouldUseWorkspaceBilling.value, + set: (value: boolean) => { + shouldUseWorkspaceBilling.value = value + } + }) + return { + useBillingRouting: () => ({ shouldUseWorkspaceBilling }) } - }) - return { - useBillingRouting: () => ({ shouldUseWorkspaceBilling }) } -}) +) const mockWorkspaceApi = vi.hoisted(() => ({ getBillingEvents: vi.fn() })) -vi.mock('@/platform/workspace/api/workspaceApi', () => ({ +vi.mock(import('@/platform/workspace/api/workspaceApi'), () => ({ workspaceApi: mockWorkspaceApi })) diff --git a/src/components/dialog/content/signin/ApiKeyForm.test.ts b/src/components/dialog/content/signin/ApiKeyForm.test.ts index b510af203f3..5e9e991a426 100644 --- a/src/components/dialog/content/signin/ApiKeyForm.test.ts +++ b/src/components/dialog/content/signin/ApiKeyForm.test.ts @@ -16,7 +16,7 @@ import ApiKeyForm from './ApiKeyForm.vue' const mockStoreApiKey = vi.fn() const mockLoadingRef = ref(false) -vi.mock('@/stores/authStore', () => ({ +vi.mock(import('@/stores/authStore'), () => ({ useAuthStore: vi.fn(() => ({ get loading() { return mockLoadingRef.value @@ -24,7 +24,7 @@ vi.mock('@/stores/authStore', () => ({ })) })) -vi.mock('@/stores/apiKeyAuthStore', () => ({ +vi.mock(import('@/stores/apiKeyAuthStore'), () => ({ useApiKeyAuthStore: vi.fn(() => ({ storeApiKey: mockStoreApiKey })) diff --git a/src/components/dialog/content/signin/SignInForm.test.ts b/src/components/dialog/content/signin/SignInForm.test.ts index 89aab51e2eb..3e23d719ae7 100644 --- a/src/components/dialog/content/signin/SignInForm.test.ts +++ b/src/components/dialog/content/signin/SignInForm.test.ts @@ -16,12 +16,12 @@ import enMessages from '@/locales/en/main.json' with { type: 'json' } import SignInForm from './SignInForm.vue' // Mock firebase auth modules -vi.mock('firebase/app', () => ({ +vi.mock(import('firebase/app'), () => ({ initializeApp: vi.fn(), getApp: vi.fn() })) -vi.mock('firebase/auth', () => ({ +vi.mock(import('firebase/auth'), () => ({ getAuth: vi.fn(), setPersistence: vi.fn(), browserLocalPersistence: {}, @@ -33,14 +33,14 @@ vi.mock('firebase/auth', () => ({ // Mock the auth composables and stores const mockSendPasswordReset = vi.fn() -vi.mock('@/composables/auth/useAuthActions', () => ({ +vi.mock(import('@/composables/auth/useAuthActions'), () => ({ useAuthActions: vi.fn(() => ({ sendPasswordReset: mockSendPasswordReset })) })) const mockLoadingRef = ref(false) -vi.mock('@/stores/authStore', () => ({ +vi.mock(import('@/stores/authStore'), () => ({ useAuthStore: vi.fn(() => ({ get loading() { return mockLoadingRef.value @@ -50,7 +50,7 @@ vi.mock('@/stores/authStore', () => ({ // Mock toast const mockToastAdd = vi.fn() -vi.mock('primevue/usetoast', () => ({ +vi.mock(import('primevue/usetoast'), () => ({ useToast: vi.fn(() => ({ add: mockToastAdd })) diff --git a/src/components/dialog/content/signin/SignUpForm.test.ts b/src/components/dialog/content/signin/SignUpForm.test.ts index 9794b031580..86cff3ab62a 100644 --- a/src/components/dialog/content/signin/SignUpForm.test.ts +++ b/src/components/dialog/content/signin/SignUpForm.test.ts @@ -13,12 +13,12 @@ import enMessages from '@/locales/en/main.json' with { type: 'json' } import SignUpForm from './SignUpForm.vue' -vi.mock('firebase/app', () => ({ +vi.mock(import('firebase/app'), () => ({ initializeApp: vi.fn(), getApp: vi.fn() })) -vi.mock('firebase/auth', () => ({ +vi.mock(import('firebase/auth'), () => ({ getAuth: vi.fn(), setPersistence: vi.fn(), browserLocalPersistence: {}, @@ -28,7 +28,7 @@ vi.mock('firebase/auth', () => ({ })) const mockLoadingRef = ref(false) -vi.mock('@/stores/authStore', () => ({ +vi.mock(import('@/stores/authStore'), () => ({ useAuthStore: vi.fn(() => ({ get loading() { return mockLoadingRef.value @@ -43,7 +43,7 @@ const mockReset = vi.fn() let emitTurnstileToken: ((token: string) => void) | undefined let emitTurnstileUnavailable: ((unavailable: boolean) => void) | undefined -vi.mock('@/composables/auth/useTurnstile', () => ({ +vi.mock(import('@/composables/auth/useTurnstile'), () => ({ useTurnstile: () => ({ enabled: mockTurnstileEnabled }), @@ -61,7 +61,7 @@ vi.mock('@/composables/auth/useTurnstile', () => ({ // The real widget loads an external Turnstile script; this stub exposes a // spyable reset() and lets a test drive the token/unavailable v-models. -vi.mock('./TurnstileWidget.vue', async () => { +vi.mock(import('./TurnstileWidget.vue'), async () => { const { defineComponent: defineMock } = await import('vue') return { default: defineMock({ diff --git a/src/components/dialog/content/signin/TurnstileWidget.test.ts b/src/components/dialog/content/signin/TurnstileWidget.test.ts index 5b54c04b373..25acd0bb77f 100644 --- a/src/components/dialog/content/signin/TurnstileWidget.test.ts +++ b/src/components/dialog/content/signin/TurnstileWidget.test.ts @@ -16,13 +16,13 @@ const { mockLoadTurnstile, mockGetSiteKey, mockLightTheme } = vi.hoisted( }) ) -vi.mock('@/composables/auth/turnstileScript', () => ({ +vi.mock(import('@/composables/auth/turnstileScript'), () => ({ loadTurnstile: mockLoadTurnstile })) -vi.mock('@/config/turnstile', () => ({ +vi.mock(import('@/config/turnstile'), () => ({ getTurnstileSiteKey: mockGetSiteKey })) -vi.mock('@/stores/workspace/colorPaletteStore', () => ({ +vi.mock(import('@/stores/workspace/colorPaletteStore'), () => ({ useColorPaletteStore: () => ({ completedActivePalette: { get light_theme() { diff --git a/src/components/dialog/content/subscription/CancelSubscriptionDialogContent.test.ts b/src/components/dialog/content/subscription/CancelSubscriptionDialogContent.test.ts index 0a45fbc1138..9e68fd643af 100644 --- a/src/components/dialog/content/subscription/CancelSubscriptionDialogContent.test.ts +++ b/src/components/dialog/content/subscription/CancelSubscriptionDialogContent.test.ts @@ -59,7 +59,7 @@ const mockCanCancel = vi.hoisted(() => ({ value: true })) const mockCanManageSubscriptionLifecycle = vi.hoisted(() => ({ value: true })) const mockDistributionTypes = vi.hoisted(() => ({ isCloud: true })) -vi.mock('@/composables/billing/useBillingContext', () => ({ +vi.mock(import('@/composables/billing/useBillingContext'), () => ({ useBillingContext: vi.fn(() => ({ cancelSubscription: mockCancelSubscription, fetchStatus: mockFetchStatus, @@ -68,50 +68,60 @@ vi.mock('@/composables/billing/useBillingContext', () => ({ })) })) -vi.mock('@/composables/billing/useBillingRouting', () => ({ +vi.mock(import('@/composables/billing/useBillingRouting'), () => ({ useBillingRouting: () => ({ shouldUseWorkspaceBilling: mockShouldUseWorkspaceBilling }) })) -vi.mock('@/platform/distribution/types', () => mockDistributionTypes) +vi.mock(import('@/platform/distribution/types'), () => mockDistributionTypes) -vi.mock('@/platform/workspace/composables/useBillingCapabilities', () => ({ - useBillingCapabilities: () => ({ - canCancel: mockCanCancel +vi.mock( + import('@/platform/workspace/composables/useBillingCapabilities'), + () => ({ + useBillingCapabilities: () => ({ + canCancel: mockCanCancel + }) }) -})) - -vi.mock('@/platform/workspace/composables/useWorkspaceUI', () => ({ - useWorkspaceUI: () => ({ - permissions: { - get value() { - return { - canManageSubscriptionLifecycle: - mockCanManageSubscriptionLifecycle.value +) + +vi.mock( + import('@/platform/workspace/composables/useWorkspaceUI'), + () => ({ + useWorkspaceUI: () => ({ + permissions: { + get value() { + return { + canManageSubscriptionLifecycle: + mockCanManageSubscriptionLifecycle.value + } } } - } + }) }) -})) +) -vi.mock('@/platform/telemetry', () => ({ +vi.mock(import('@/platform/telemetry'), () => ({ useTelemetry: () => ({ trackSubscriptionCancellation: mockTrackCancellation }) })) -vi.mock('@/stores/dialogStore', () => ({ +vi.mock(import('@/stores/dialogStore'), () => ({ useDialogStore: vi.fn(() => ({ closeDialog: mockCloseDialog })) })) -vi.mock('primevue/usetoast', () => ({ - useToast: vi.fn(() => ({ - add: mockToastAdd - })) -})) +vi.mock( + import('primevue/usetoast'), // eslint-disable-line primevue-removal/no-imports + + () => ({ + useToast: vi.fn(() => ({ + add: mockToastAdd + })) + }) +) function renderComponent( props: { cancelAt?: string; flowAlreadyOpened?: boolean } = {} diff --git a/src/components/error/ErrorOverlay.test.ts b/src/components/error/ErrorOverlay.test.ts index 67a35e7ea6d..22a653a65ef 100644 --- a/src/components/error/ErrorOverlay.test.ts +++ b/src/components/error/ErrorOverlay.test.ts @@ -25,15 +25,18 @@ const mockErrorGroups = vi.hoisted(() => ({ const mockAllErrorGroups = mockErrorGroups.allErrorGroups -vi.mock('@/components/rightSidePanel/errors/useErrorGroups', () => ({ - useErrorGroups: () => mockErrorGroups -})) +vi.mock( + import('@/components/rightSidePanel/errors/useErrorGroups'), + () => ({ + useErrorGroups: () => mockErrorGroups + }) +) -vi.mock('@/composables/graph/useNodeErrorFlagSync', () => ({ +vi.mock(import('@/composables/graph/useNodeErrorFlagSync'), () => ({ useNodeErrorFlagSync: vi.fn() })) -vi.mock('@/scripts/app', () => ({ +vi.mock(import('@/scripts/app'), () => ({ app: { isGraphReady: false, rootGraph: { @@ -43,7 +46,7 @@ vi.mock('@/scripts/app', () => ({ } })) -vi.mock('@/utils/graphTraversalUtil', () => ({ +vi.mock(import('@/utils/graphTraversalUtil'), () => ({ executionIdToNodeLocatorId: vi.fn((id: string) => id), getActiveGraphNodeIds: vi.fn(() => new Set()), getExecutionIdByNode: vi.fn(), @@ -51,7 +54,7 @@ vi.mock('@/utils/graphTraversalUtil', () => ({ })) const mockOpenPanel = vi.hoisted(() => vi.fn()) -vi.mock('@/stores/workspace/rightSidePanelStore', () => ({ +vi.mock(import('@/stores/workspace/rightSidePanelStore'), () => ({ useRightSidePanelStore: () => ({ openPanel: mockOpenPanel }) })) @@ -61,7 +64,7 @@ const mockCanvasStore = vi.hoisted(() => ({ currentGraph: null, updateSelectedItems: vi.fn() })) -vi.mock('@/renderer/core/canvas/canvasStore', () => ({ +vi.mock(import('@/renderer/core/canvas/canvasStore'), () => ({ useCanvasStore: () => mockCanvasStore })) diff --git a/src/components/error/useErrorOverlayState.test.ts b/src/components/error/useErrorOverlayState.test.ts index 8dfaa2b63d0..8ed4c8612d3 100644 --- a/src/components/error/useErrorOverlayState.test.ts +++ b/src/components/error/useErrorOverlayState.test.ts @@ -26,15 +26,18 @@ const mockErrorGroups = vi.hoisted(() => ({ const mockAllErrorGroups = mockErrorGroups.allErrorGroups -vi.mock('@/components/rightSidePanel/errors/useErrorGroups', () => ({ - useErrorGroups: () => mockErrorGroups -})) +vi.mock( + import('@/components/rightSidePanel/errors/useErrorGroups'), + () => ({ + useErrorGroups: () => mockErrorGroups + }) +) -vi.mock('@/composables/graph/useNodeErrorFlagSync', () => ({ +vi.mock(import('@/composables/graph/useNodeErrorFlagSync'), () => ({ useNodeErrorFlagSync: vi.fn() })) -vi.mock('@/scripts/app', () => ({ +vi.mock(import('@/scripts/app'), () => ({ app: { isGraphReady: false, rootGraph: { @@ -44,7 +47,7 @@ vi.mock('@/scripts/app', () => ({ } })) -vi.mock('@/utils/graphTraversalUtil', () => ({ +vi.mock(import('@/utils/graphTraversalUtil'), () => ({ executionIdToNodeLocatorId: vi.fn((id: string) => id), getActiveGraphNodeIds: vi.fn(() => new Set()), getExecutionIdByNode: vi.fn(), diff --git a/src/components/hdr/HdrViewerContent.test.ts b/src/components/hdr/HdrViewerContent.test.ts index 7d7166900c5..76c1d6b4b40 100644 --- a/src/components/hdr/HdrViewerContent.test.ts +++ b/src/components/hdr/HdrViewerContent.test.ts @@ -6,10 +6,10 @@ import { createI18n } from 'vue-i18n' import HdrViewerContent from './HdrViewerContent.vue' -vi.mock('@/base/common/downloadUtil', () => ({ downloadFile: vi.fn() })) +vi.mock(import('@/base/common/downloadUtil'), () => ({ downloadFile: vi.fn() })) const holder = vi.hoisted(() => ({ viewer: undefined as unknown })) -vi.mock('@/composables/useHdrViewer', () => ({ +vi.mock(import('@/composables/useHdrViewer'), () => ({ useHdrViewer: () => holder.viewer, CHANNEL_MODES: ['rgb', 'r', 'g', 'b', 'a', 'luminance'] })) diff --git a/src/components/helpcenter/HelpCenterMenuContent.test.ts b/src/components/helpcenter/HelpCenterMenuContent.test.ts index 88f131cdb66..e709eb2123e 100644 --- a/src/components/helpcenter/HelpCenterMenuContent.test.ts +++ b/src/components/helpcenter/HelpCenterMenuContent.test.ts @@ -16,7 +16,7 @@ const distribution = vi.hoisted(() => ({ const commandStoreExecute = vi.hoisted(() => vi.fn()) -vi.mock('@/platform/distribution/types', () => ({ +vi.mock(import('@/platform/distribution/types'), () => ({ get isCloud() { return distribution.isCloud }, @@ -28,7 +28,7 @@ vi.mock('@/platform/distribution/types', () => ({ } })) -vi.mock('@/composables/useExternalLink', () => ({ +vi.mock(import('@/composables/useExternalLink'), () => ({ useExternalLink: () => ({ staticUrls: { discord: '', @@ -39,13 +39,13 @@ vi.mock('@/composables/useExternalLink', () => ({ }) })) -vi.mock('@/platform/settings/settingStore', () => ({ +vi.mock(import('@/platform/settings/settingStore'), () => ({ useSettingStore: () => ({ get: () => false }) })) -vi.mock('@/platform/telemetry', () => ({ +vi.mock(import('@/platform/telemetry'), () => ({ useTelemetry: () => ({ trackHelpResourceClicked: vi.fn(), trackHelpCenterOpened: vi.fn(), @@ -53,7 +53,7 @@ vi.mock('@/platform/telemetry', () => ({ }) })) -vi.mock('@/platform/updates/common/releaseStore', () => ({ +vi.mock(import('@/platform/updates/common/releaseStore'), () => ({ useReleaseStore: () => ({ releases: [], recentReleases: [], @@ -62,34 +62,47 @@ vi.mock('@/platform/updates/common/releaseStore', () => ({ }) })) -vi.mock('@/stores/commandStore', () => ({ +vi.mock(import('@/stores/commandStore'), () => ({ useCommandStore: () => ({ execute: commandStoreExecute }) })) -vi.mock('@/utils/envUtil', () => ({ +vi.mock(import('@/utils/envUtil'), () => ({ electronAPI: () => null })) -vi.mock( - '@/workbench/extensions/manager/composables/useConflictAcknowledgment', +vi.mock( + import('@/workbench/extensions/manager/composables/useConflictAcknowledgment'), + () => ({ useConflictAcknowledgment: () => ({ shouldShowRedDot: { value: false } }) }) ) -vi.mock('@/workbench/extensions/manager/composables/useManagerState', () => ({ - useManagerState: () => ({ isNewManagerUI: { value: false } }) -})) +vi.mock( + import('@/workbench/extensions/manager/composables/useManagerState'), -vi.mock('@/workbench/extensions/manager/services/comfyManagerService', () => ({ - useComfyManagerService: () => ({}) -})) + () => ({ + useManagerState: () => ({ isNewManagerUI: { value: false } }) + }) +) -vi.mock('primevue/usetoast', () => ({ - useToast: () => ({ add: vi.fn() }) -})) +vi.mock( + import('@/workbench/extensions/manager/services/comfyManagerService'), + + () => ({ + useComfyManagerService: () => ({}) + }) +) + +vi.mock( + import('primevue/usetoast'), // eslint-disable-line primevue-removal/no-imports + + () => ({ + useToast: () => ({ add: vi.fn() }) + }) +) -vi.mock('@/components/icons/PuzzleIcon.vue', () => ({ +vi.mock(import('@/components/icons/PuzzleIcon.vue'), () => ({ default: defineComponent({ name: 'PuzzleIconStub', render: () => h('div') diff --git a/src/components/imagecrop/WidgetImageCrop.test.ts b/src/components/imagecrop/WidgetImageCrop.test.ts index d4e8bcaddaf..c5dbe1a9fec 100644 --- a/src/components/imagecrop/WidgetImageCrop.test.ts +++ b/src/components/imagecrop/WidgetImageCrop.test.ts @@ -32,7 +32,7 @@ function createDefaultCropState() { } } -vi.mock('@/composables/useImageCrop', async () => { +vi.mock(import('@/composables/useImageCrop'), async () => { return { ASPECT_RATIOS: { '1:1': 1, @@ -52,7 +52,7 @@ const upstreamHolder = vi.hoisted(() => ({ ref: null as Ref | null })) -vi.mock('@/composables/useUpstreamValue', async () => { +vi.mock(import('@/composables/useUpstreamValue'), async () => { const { ref } = await import('vue') return { useUpstreamValue: () => { diff --git a/src/components/node/NodeHelpContent.test.ts b/src/components/node/NodeHelpContent.test.ts index 0070596a533..55a123dffed 100644 --- a/src/components/node/NodeHelpContent.test.ts +++ b/src/components/node/NodeHelpContent.test.ts @@ -7,7 +7,7 @@ import { ComfyNodeDefImpl } from '@/stores/nodeDefStore' import NodeHelpContent from './NodeHelpContent.vue' -vi.mock('@/composables/useNodeHelpContent', () => ({ +vi.mock(import('@/composables/useNodeHelpContent'), () => ({ useNodeHelpContent: () => ({ renderedHelpHtml: ref(''), isLoading: ref(false), diff --git a/src/components/node/NodePreviewCard.test.ts b/src/components/node/NodePreviewCard.test.ts index f47d5fb3d4c..bbc54092918 100644 --- a/src/components/node/NodePreviewCard.test.ts +++ b/src/components/node/NodePreviewCard.test.ts @@ -7,8 +7,9 @@ import { ComfyNodeDefImpl } from '@/stores/nodeDefStore' import NodePreviewCard from './NodePreviewCard.vue' -vi.mock( - '@/renderer/extensions/vueNodes/components/LGraphNodePreview.vue', +vi.mock( + import('@/renderer/extensions/vueNodes/components/LGraphNodePreview.vue'), + () => ({ default: { template: '
' } }) diff --git a/src/components/painter/WidgetPainter.test.ts b/src/components/painter/WidgetPainter.test.ts index eb95c5fe6ab..c3ff8949618 100644 --- a/src/components/painter/WidgetPainter.test.ts +++ b/src/components/painter/WidgetPainter.test.ts @@ -6,7 +6,7 @@ import { createI18n } from 'vue-i18n' const sizeHolder = vi.hoisted(() => ({ width: 0, height: 0 })) -vi.mock('@vueuse/core', () => ({ +vi.mock(import('@vueuse/core'), () => ({ reactiveOmit: (value: object) => value, useElementSize: () => ({ width: ref(sizeHolder.width), @@ -42,7 +42,7 @@ function createDefaultPainterState() { } } -vi.mock('@/composables/painter/usePainter', () => ({ +vi.mock(import('@/composables/painter/usePainter'), () => ({ PAINTER_TOOLS: { BRUSH: 'brush', ERASER: 'eraser' } as const, usePainter: () => { if (!painterHolder.state) painterHolder.state = createDefaultPainterState() diff --git a/src/components/queue/JobHistoryActionsMenu.test.ts b/src/components/queue/JobHistoryActionsMenu.test.ts index d5c1a3e913e..e4ec166a383 100644 --- a/src/components/queue/JobHistoryActionsMenu.test.ts +++ b/src/components/queue/JobHistoryActionsMenu.test.ts @@ -5,9 +5,9 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' import { popoverCloseSpy } from '@/components/ui/__mocks__/popoverMockState' import { i18n } from '@/i18n' -vi.mock('@/components/ui/Popover.vue') +vi.mock(import('@/components/ui/Popover.vue')) -vi.mock('@/platform/distribution/types', () => ({ +vi.mock(import('@/platform/distribution/types'), () => ({ isCloud: false })) @@ -22,7 +22,7 @@ const mockSidebarTabStore = { activeSidebarTabId: null as string | null } -vi.mock('@/platform/settings/settingStore', () => ({ +vi.mock(import('@/platform/settings/settingStore'), () => ({ useSettingStore: () => ({ get: mockGetSetting, set: mockSetSetting, @@ -30,7 +30,7 @@ vi.mock('@/platform/settings/settingStore', () => ({ }) })) -vi.mock('@/stores/workspace/sidebarTabStore', () => ({ +vi.mock(import('@/stores/workspace/sidebarTabStore'), () => ({ useSidebarTabStore: () => mockSidebarTabStore })) diff --git a/src/components/queue/QueueInlineProgress.test.ts b/src/components/queue/QueueInlineProgress.test.ts index 66e9dde2bbe..bd41cc38445 100644 --- a/src/components/queue/QueueInlineProgress.test.ts +++ b/src/components/queue/QueueInlineProgress.test.ts @@ -10,7 +10,7 @@ const mockProgress = vi.hoisted(() => ({ currentNodePercent: null! as Ref })) -vi.mock('@/composables/queue/useQueueProgress', () => ({ +vi.mock(import('@/composables/queue/useQueueProgress'), () => ({ useQueueProgress: () => ({ totalPercent: mockProgress.totalPercent, currentNodePercent: mockProgress.currentNodePercent diff --git a/src/components/queue/QueueOverlayExpanded.test.ts b/src/components/queue/QueueOverlayExpanded.test.ts index a13b7ae31c0..b06c7621bec 100644 --- a/src/components/queue/QueueOverlayExpanded.test.ts +++ b/src/components/queue/QueueOverlayExpanded.test.ts @@ -5,11 +5,11 @@ import { describe, expect, it, vi } from 'vitest' import type { JobListItem } from '@/composables/queue/useJobList' -vi.mock('@/composables/queue/useJobMenu', () => ({ +vi.mock(import('@/composables/queue/useJobMenu'), () => ({ useJobMenu: () => ({ jobMenuEntries: [] }) })) -vi.mock('@/composables/useErrorHandling', () => ({ +vi.mock(import('@/composables/useErrorHandling'), () => ({ useErrorHandling: () => ({ wrapWithErrorHandlingAsync: unknown>( fn: T diff --git a/src/components/queue/QueueOverlayHeader.test.ts b/src/components/queue/QueueOverlayHeader.test.ts index 182443dedaa..f4247016da2 100644 --- a/src/components/queue/QueueOverlayHeader.test.ts +++ b/src/components/queue/QueueOverlayHeader.test.ts @@ -5,7 +5,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' import { popoverCloseSpy } from '@/components/ui/__mocks__/popoverMockState' import { i18n } from '@/i18n' -vi.mock('@/components/ui/Popover.vue') +vi.mock(import('@/components/ui/Popover.vue')) const mockGetSetting = vi.fn<(key: string) => boolean | undefined>((key) => key === 'Comfy.Queue.QPOV2' || key === 'Comfy.Queue.ShowRunProgressBar' @@ -18,7 +18,7 @@ const mockSidebarTabStore = { activeSidebarTabId: null as string | null } -vi.mock('@/platform/settings/settingStore', () => ({ +vi.mock(import('@/platform/settings/settingStore'), () => ({ useSettingStore: () => ({ get: mockGetSetting, set: mockSetSetting, @@ -26,7 +26,7 @@ vi.mock('@/platform/settings/settingStore', () => ({ }) })) -vi.mock('@/stores/workspace/sidebarTabStore', () => ({ +vi.mock(import('@/stores/workspace/sidebarTabStore'), () => ({ useSidebarTabStore: () => mockSidebarTabStore })) diff --git a/src/components/queue/QueueProgressOverlay.test.ts b/src/components/queue/QueueProgressOverlay.test.ts index 067c8084d9b..fe5b4f334b9 100644 --- a/src/components/queue/QueueProgressOverlay.test.ts +++ b/src/components/queue/QueueProgressOverlay.test.ts @@ -10,7 +10,7 @@ import type { JobStatus } from '@/platform/remote/comfyui/jobs/jobTypes' import { TaskItemImpl, useQueueStore } from '@/stores/queueStore' import { useSidebarTabStore } from '@/stores/workspace/sidebarTabStore' -vi.mock('@/platform/distribution/types', () => ({ +vi.mock(import('@/platform/distribution/types'), () => ({ isCloud: false })) diff --git a/src/components/queue/job/JobAssetsList.test.ts b/src/components/queue/job/JobAssetsList.test.ts index 489efac2e17..f29e9be8475 100644 --- a/src/components/queue/job/JobAssetsList.test.ts +++ b/src/components/queue/job/JobAssetsList.test.ts @@ -4,11 +4,13 @@ import { fireEvent, render, screen } from '@testing-library/vue' import userEvent from '@testing-library/user-event' import { describe, expect, it, vi } from 'vitest' import { defineComponent, nextTick } from 'vue' +import { createI18n } from 'vue-i18n' import type * as RekaUi from 'reka-ui' import './testUtils/mockTanstackVirtualizer' import type { JobGroup, JobListItem } from '@/composables/queue/useJobList' +import enMessages from '@/locales/en/main.json' with { type: 'json' } import JobAssetsList from './JobAssetsList.vue' @@ -24,11 +26,14 @@ const hoisted = vi.hoisted(() => ({ } })) -vi.mock('@/components/queue/job/JobDetailsPopover.vue', () => ({ - default: hoisted.jobDetailsPopoverStub -})) +vi.mock( + import('@/components/queue/job/JobDetailsPopover.vue'), + () => ({ + default: hoisted.jobDetailsPopoverStub + }) +) -vi.mock('reka-ui', async (importOriginal) => { +vi.mock(import('reka-ui'), async (importOriginal) => { const actual = await importOriginal() const { computed, defineComponent, h, inject, provide } = await import('vue') const popoverOpenKey = Symbol('popoverOpen') @@ -135,19 +140,10 @@ const AssetsListItemStub = defineComponent({ ` }) -vi.mock('vue-i18n', () => { - return { - createI18n: () => ({ - global: { - t: (key: string) => key, - te: () => true, - d: (value: string) => value - } - }), - useI18n: () => ({ - t: (key: string) => key - }) - } +const i18n = createI18n({ + legacy: false, + locale: 'en', + messages: { en: enMessages } }) type TestPreviewOutput = { @@ -225,6 +221,7 @@ function renderJobAssetsList({ }, attrs, global: { + plugins: [i18n], stubs: { teleport: true, AssetsListItem: AssetsListItemStub @@ -374,7 +371,7 @@ describe('JobAssetsList', () => { const jobRow = container.querySelector(`[data-job-id="${job.id}"]`)! await fireEvent.mouseEnter(jobRow) - await fireEvent.click(screen.getByText('menuLabels.View')) + await fireEvent.click(screen.getByText('View')) await nextTick() expect(onViewItem).toHaveBeenCalledWith(job) diff --git a/src/components/queue/job/JobFiltersBar.test.ts b/src/components/queue/job/JobFiltersBar.test.ts index de74df7d9c3..0b61f449ffa 100644 --- a/src/components/queue/job/JobFiltersBar.test.ts +++ b/src/components/queue/job/JobFiltersBar.test.ts @@ -4,21 +4,25 @@ import { describe, expect, it, vi } from 'vitest' import { createI18n } from 'vue-i18n' import { defineComponent } from 'vue' -vi.mock('primevue/popover', () => { - const PopoverStub = defineComponent({ - name: 'Popover', - setup(_, { slots, expose }) { - expose({ - hide: () => undefined, - toggle: (_event: Event) => undefined - }) - return () => slots.default?.() - } - }) - return { default: PopoverStub } -}) +vi.mock( + import('primevue/popover'), // eslint-disable-line primevue-removal/no-imports + + () => { + const PopoverStub = defineComponent({ + name: 'Popover', + setup(_, { slots, expose }) { + expose({ + hide: () => undefined, + toggle: (_event: Event) => undefined + }) + return () => slots.default?.() + } + }) + return { default: PopoverStub } + } +) -vi.mock('@/platform/distribution/types', () => ({ +vi.mock(import('@/platform/distribution/types'), () => ({ isCloud: false })) diff --git a/src/components/queue/job/testUtils/mockTanstackVirtualizer.ts b/src/components/queue/job/testUtils/mockTanstackVirtualizer.ts index e07c5f6ea8f..424eca3b63d 100644 --- a/src/components/queue/job/testUtils/mockTanstackVirtualizer.ts +++ b/src/components/queue/job/testUtils/mockTanstackVirtualizer.ts @@ -1,6 +1,6 @@ import { vi } from 'vitest' -vi.mock('@tanstack/vue-virtual', async () => { +vi.mock(import('@tanstack/vue-virtual'), async () => { const { computed } = await import('vue') return { diff --git a/src/components/range/WidgetRange.test.ts b/src/components/range/WidgetRange.test.ts index 4dec19ce7af..32176b81665 100644 --- a/src/components/range/WidgetRange.test.ts +++ b/src/components/range/WidgetRange.test.ts @@ -15,7 +15,7 @@ const upstreamHolder = vi.hoisted(() => ({ ref: null as { value: unknown } | null })) -vi.mock('@/composables/useUpstreamValue', async () => { +vi.mock(import('@/composables/useUpstreamValue'), async () => { const { ref } = await import('vue') return { useUpstreamValue: () => { @@ -30,7 +30,7 @@ const outputsHolder = vi.hoisted(() => ({ nodeOutputs: {} as Record })) -vi.mock('@/stores/nodeOutputStore', () => ({ +vi.mock(import('@/stores/nodeOutputStore'), () => ({ useNodeOutputStore: () => outputsHolder })) diff --git a/src/components/rightSidePanel/RightSidePanel.test.ts b/src/components/rightSidePanel/RightSidePanel.test.ts index 463379c615d..ffa8fbe1411 100644 --- a/src/components/rightSidePanel/RightSidePanel.test.ts +++ b/src/components/rightSidePanel/RightSidePanel.test.ts @@ -26,15 +26,17 @@ const mockApp = vi.hoisted(() => ({ rootGraph: null as LGraph | null })) -vi.mock('@/scripts/app', () => ({ app: mockApp })) +vi.mock(import('@/scripts/app'), () => ({ app: mockApp })) -vi.mock('@/composables/graph/useGraphHierarchy', () => ({ +vi.mock(import('@/composables/graph/useGraphHierarchy'), () => ({ useGraphHierarchy: () => ({ findParentGroup: vi.fn(() => null) }) })) -vi.mock('@/platform/telemetry', () => ({ useTelemetry: () => undefined })) +vi.mock(import('@/platform/telemetry'), () => ({ + useTelemetry: () => undefined +})) -vi.mock('@/platform/settings/settingStore', () => ({ +vi.mock(import('@/platform/settings/settingStore'), () => ({ useSettingStore: () => ({ get: (key: string) => { if (key === 'Comfy.RightSidePanel.ShowErrorsTab') return true diff --git a/src/components/rightSidePanel/errors/ErrorGroupList.test.ts b/src/components/rightSidePanel/errors/ErrorGroupList.test.ts index d466ef98bc3..39edd522878 100644 --- a/src/components/rightSidePanel/errors/ErrorGroupList.test.ts +++ b/src/components/rightSidePanel/errors/ErrorGroupList.test.ts @@ -19,7 +19,7 @@ import { toNodeId } from '@/types/nodeId' import ErrorGroupList from './ErrorGroupList.vue' -vi.mock('@/scripts/app', () => { +vi.mock(import('@/scripts/app'), () => { const rootGraph = { serialize: vi.fn(() => ({})), getNodeById: vi.fn() @@ -32,7 +32,7 @@ vi.mock('@/scripts/app', () => { } }) -vi.mock('@/utils/graphTraversalUtil', () => ({ +vi.mock(import('@/utils/graphTraversalUtil'), () => ({ getNodeByExecutionId: vi.fn(), getExecutionIdByNode: vi.fn(), getRootParentNode: vi.fn(() => null), @@ -40,17 +40,17 @@ vi.mock('@/utils/graphTraversalUtil', () => ({ mapAllNodes: vi.fn(() => []) })) -vi.mock('@/utils/litegraphUtil', () => ({ +vi.mock(import('@/utils/litegraphUtil'), () => ({ isLGraphNode: vi.fn(() => false) })) -vi.mock('@/composables/useCopyToClipboard', () => ({ +vi.mock(import('@/composables/useCopyToClipboard'), () => ({ useCopyToClipboard: vi.fn(() => ({ copyToClipboard: vi.fn() })) })) -vi.mock('@/platform/missingModel/missingModelDownload', () => ({ +vi.mock(import('@/platform/missingModel/missingModelDownload'), () => ({ downloadModel: vi.fn(), fetchModelMetadata: vi.fn().mockResolvedValue({ fileSize: null, diff --git a/src/components/rightSidePanel/errors/ErrorNodeCard.test.ts b/src/components/rightSidePanel/errors/ErrorNodeCard.test.ts index 0477101b929..59717a1d674 100644 --- a/src/components/rightSidePanel/errors/ErrorNodeCard.test.ts +++ b/src/components/rightSidePanel/errors/ErrorNodeCard.test.ts @@ -17,13 +17,13 @@ const mockGenerateErrorReport = vi.fn( (_data?: unknown) => '# ComfyUI Error Report\n...' ) -vi.mock('@/scripts/api', () => ({ +vi.mock(import('@/scripts/api'), () => ({ api: { getLogs: () => mockGetLogs() } })) -vi.mock('@/scripts/app', () => ({ +vi.mock(import('@/scripts/app'), () => ({ app: { rootGraph: { serialize: () => mockSerialize() @@ -31,13 +31,13 @@ vi.mock('@/scripts/app', () => ({ } })) -vi.mock('@/utils/errorReportUtil', () => ({ +vi.mock(import('@/utils/errorReportUtil'), () => ({ generateErrorReport: (data: unknown) => mockGenerateErrorReport(data) })) const mockTrackHelpResourceClicked = vi.fn() -vi.mock('@/platform/telemetry', () => ({ +vi.mock(import('@/platform/telemetry'), () => ({ useTelemetry: vi.fn(() => ({ trackUiButtonClicked: vi.fn(), trackHelpResourceClicked: mockTrackHelpResourceClicked @@ -45,13 +45,13 @@ vi.mock('@/platform/telemetry', () => ({ })) const mockExecuteCommand = vi.fn() -vi.mock('@/stores/commandStore', () => ({ +vi.mock(import('@/stores/commandStore'), () => ({ useCommandStore: vi.fn(() => ({ execute: mockExecuteCommand })) })) -vi.mock('@/composables/useExternalLink', () => ({ +vi.mock(import('@/composables/useExternalLink'), () => ({ useExternalLink: vi.fn(() => ({ staticUrls: { githubIssues: 'https://github.com/Comfy-Org/ComfyUI/issues' diff --git a/src/components/rightSidePanel/errors/MissingNodeCard.test.ts b/src/components/rightSidePanel/errors/MissingNodeCard.test.ts index d36aa7275f8..d7d45862440 100644 --- a/src/components/rightSidePanel/errors/MissingNodeCard.test.ts +++ b/src/components/rightSidePanel/errors/MissingNodeCard.test.ts @@ -7,7 +7,7 @@ import { createI18n } from 'vue-i18n' import type { MissingPackGroup } from '@/components/rightSidePanel/errors/useErrorGroups' const mockIsCloud = vi.hoisted(() => ({ value: false })) -vi.mock('@/platform/distribution/types', () => ({ +vi.mock(import('@/platform/distribution/types'), () => ({ get isCloud() { return mockIsCloud.value } @@ -20,8 +20,9 @@ const mockSystemStats = vi.hoisted(() => ({ value: null as { system?: { comfyui_version?: string } } | null })) -vi.mock( - '@/workbench/extensions/manager/composables/nodePack/useMissingNodes', +vi.mock( + import('@/workbench/extensions/manager/composables/nodePack/useMissingNodes'), + () => ({ useMissingNodes: () => ({ missingCoreNodes: mockMissingCoreNodes, @@ -33,7 +34,7 @@ vi.mock( }) ) -vi.mock('@/stores/systemStatsStore', () => ({ +vi.mock(import('@/stores/systemStatsStore'), () => ({ useSystemStatsStore: () => ({ get systemStats() { return mockSystemStats.value @@ -43,30 +44,42 @@ vi.mock('@/stores/systemStatsStore', () => ({ const mockApplyChanges = vi.hoisted(() => vi.fn()) const mockIsRestarting = vi.hoisted(() => ({ value: false })) -vi.mock('@/workbench/extensions/manager/composables/useApplyChanges', () => ({ - useApplyChanges: () => ({ - get isRestarting() { - return mockIsRestarting.value - }, - applyChanges: mockApplyChanges +vi.mock( + import('@/workbench/extensions/manager/composables/useApplyChanges'), + + () => ({ + useApplyChanges: () => ({ + get isRestarting() { + return mockIsRestarting.value + }, + applyChanges: mockApplyChanges + }) }) -})) +) const mockIsPackInstalled = vi.hoisted(() => vi.fn(() => false)) -vi.mock('@/workbench/extensions/manager/stores/comfyManagerStore', () => ({ - useComfyManagerStore: () => ({ - isPackInstalled: mockIsPackInstalled +vi.mock( + import('@/workbench/extensions/manager/stores/comfyManagerStore'), + + () => ({ + useComfyManagerStore: () => ({ + isPackInstalled: mockIsPackInstalled + }) }) -})) +) const mockShouldShowManagerButtons = vi.hoisted(() => ({ value: false })) -vi.mock('@/workbench/extensions/manager/composables/useManagerState', () => ({ - useManagerState: () => ({ - shouldShowManagerButtons: mockShouldShowManagerButtons +vi.mock( + import('@/workbench/extensions/manager/composables/useManagerState'), + + () => ({ + useManagerState: () => ({ + shouldShowManagerButtons: mockShouldShowManagerButtons + }) }) -})) +) -vi.mock('./MissingPackGroupRow.vue', () => ({ +vi.mock(import('./MissingPackGroupRow.vue'), () => ({ default: { name: 'MissingPackGroupRow', template: `
>([]) const mockIsLoading = ref(false) -vi.mock( - '@/workbench/extensions/manager/composables/nodePack/useMissingNodes', +vi.mock( + import('@/workbench/extensions/manager/composables/nodePack/useMissingNodes'), + () => ({ useMissingNodes: () => ({ missingNodePacks: mockMissingNodePacks, @@ -26,8 +27,9 @@ vi.mock( }) ) -vi.mock( - '@/workbench/extensions/manager/composables/nodePack/usePackInstall', +vi.mock( + import('@/workbench/extensions/manager/composables/nodePack/usePackInstall'), + () => ({ usePackInstall: () => ({ isInstalling: mockIsInstalling, @@ -36,22 +38,34 @@ vi.mock( }) ) -vi.mock('@/workbench/extensions/manager/stores/comfyManagerStore', () => ({ - useComfyManagerStore: () => ({ - isPackInstalled: mockIsPackInstalled +vi.mock( + import('@/workbench/extensions/manager/stores/comfyManagerStore'), + + () => ({ + useComfyManagerStore: () => ({ + isPackInstalled: mockIsPackInstalled + }) }) -})) +) + +vi.mock( + import('@/workbench/extensions/manager/composables/useManagerState'), -vi.mock('@/workbench/extensions/manager/composables/useManagerState', () => ({ - useManagerState: () => ({ - shouldShowManagerButtons: mockShouldShowManagerButtons, - openManager: mockOpenManager + () => ({ + useManagerState: () => ({ + shouldShowManagerButtons: mockShouldShowManagerButtons, + openManager: mockOpenManager + }) }) -})) +) + +vi.mock( + import('@/workbench/extensions/manager/types/comfyManagerTypes'), -vi.mock('@/workbench/extensions/manager/types/comfyManagerTypes', () => ({ - ManagerTab: { Missing: 'missing', All: 'all' } -})) + () => ({ + ManagerTab: { Missing: 'missing', All: 'all' } + }) +) import MissingPackGroupRow from './MissingPackGroupRow.vue' diff --git a/src/components/rightSidePanel/errors/TabErrors.test.ts b/src/components/rightSidePanel/errors/TabErrors.test.ts index 166efb4f40c..9202df320c8 100644 --- a/src/components/rightSidePanel/errors/TabErrors.test.ts +++ b/src/components/rightSidePanel/errors/TabErrors.test.ts @@ -29,7 +29,7 @@ const { mockFocusNode, mockRefreshMissingModels } = vi.hoisted(() => ({ mockRefreshMissingModels: vi.fn() })) -vi.mock('@/scripts/app', () => { +vi.mock(import('@/scripts/app'), () => { const rootGraph = { serialize: vi.fn(() => ({})), getNodeById: vi.fn() @@ -43,7 +43,7 @@ vi.mock('@/scripts/app', () => { } }) -vi.mock('@/utils/graphTraversalUtil', () => ({ +vi.mock(import('@/utils/graphTraversalUtil'), () => ({ collectAllNodes: vi.fn(() => []), getNodeByExecutionId: vi.fn(), getActiveGraphNodeIds: vi.fn(() => new Set()), @@ -52,13 +52,13 @@ vi.mock('@/utils/graphTraversalUtil', () => ({ mapAllNodes: vi.fn(() => []) })) -vi.mock('@/composables/useCopyToClipboard', () => ({ +vi.mock(import('@/composables/useCopyToClipboard'), () => ({ useCopyToClipboard: vi.fn(() => ({ copyToClipboard: vi.fn() })) })) -vi.mock('@/composables/canvas/useFocusNode', () => ({ +vi.mock(import('@/composables/canvas/useFocusNode'), () => ({ useFocusNode: vi.fn(() => ({ focusNode: mockFocusNode })) @@ -67,7 +67,7 @@ vi.mock('@/composables/canvas/useFocusNode', () => ({ // Its pack lookup resolves after the test file ends, and the console.warn on a // rejection lands while the worker's rpc is closing - an unhandled error that // fails the whole run with every test green. Mocked as the sibling suites do. -vi.mock('@/stores/comfyRegistryStore', () => ({ +vi.mock(import('@/stores/comfyRegistryStore'), () => ({ useComfyRegistryStore: () => ({ inferPackFromNodeName: vi.fn(), // TabErrors mounts the node-pack tree, which cancels this on unmount. @@ -75,7 +75,7 @@ vi.mock('@/stores/comfyRegistryStore', () => ({ }) })) -vi.mock('@/platform/missingModel/missingModelDownload', () => ({ +vi.mock(import('@/platform/missingModel/missingModelDownload'), () => ({ downloadModel: vi.fn(), fetchModelMetadata: vi.fn(async () => ({ fileSize: null, diff --git a/src/components/rightSidePanel/errors/swapNodeGroups.test.ts b/src/components/rightSidePanel/errors/swapNodeGroups.test.ts index 10fbb4395ab..98385ae3103 100644 --- a/src/components/rightSidePanel/errors/swapNodeGroups.test.ts +++ b/src/components/rightSidePanel/errors/swapNodeGroups.test.ts @@ -4,7 +4,7 @@ import { describe, expect, it, vi } from 'vitest' import type { MissingNodeType } from '@/types/comfy' -vi.mock('@/scripts/app', () => ({ +vi.mock(import('@/scripts/app'), () => ({ app: { rootGraph: { serialize: vi.fn(() => ({})), @@ -13,7 +13,7 @@ vi.mock('@/scripts/app', () => ({ } })) -vi.mock('@/utils/graphTraversalUtil', () => ({ +vi.mock(import('@/utils/graphTraversalUtil'), () => ({ getNodeByExecutionId: vi.fn(), getExecutionIdByNode: vi.fn(), getRootParentNode: vi.fn(() => null), @@ -21,27 +21,27 @@ vi.mock('@/utils/graphTraversalUtil', () => ({ mapAllNodes: vi.fn(() => []) })) -vi.mock('@/platform/distribution/types', () => ({ +vi.mock(import('@/platform/distribution/types'), () => ({ isCloud: false })) -vi.mock('@/i18n', () => ({ +vi.mock(import('@/i18n'), () => ({ te: vi.fn(() => false), t: vi.fn((key: string) => key), st: vi.fn((_key: string, fallback: string) => fallback) })) -vi.mock('@/stores/comfyRegistryStore', () => ({ +vi.mock(import('@/stores/comfyRegistryStore'), () => ({ useComfyRegistryStore: () => ({ inferPackFromNodeName: vi.fn() }) })) -vi.mock('@/utils/nodeTitleUtil', () => ({ +vi.mock(import('@/utils/nodeTitleUtil'), () => ({ resolveNodeDisplayName: vi.fn(() => '') })) -vi.mock('@/utils/litegraphUtil', () => ({ +vi.mock(import('@/utils/litegraphUtil'), () => ({ isLGraphNode: vi.fn(() => false) })) diff --git a/src/components/rightSidePanel/errors/useErrorActions.test.ts b/src/components/rightSidePanel/errors/useErrorActions.test.ts index cf1ab854fb9..7357761dea3 100644 --- a/src/components/rightSidePanel/errors/useErrorActions.test.ts +++ b/src/components/rightSidePanel/errors/useErrorActions.test.ts @@ -15,19 +15,19 @@ const mocks = vi.hoisted(() => ({ } })) -vi.mock('@/stores/commandStore', () => ({ +vi.mock(import('@/stores/commandStore'), () => ({ useCommandStore: () => ({ execute: mocks.execute }) })) -vi.mock('@/composables/useExternalLink', () => ({ +vi.mock(import('@/composables/useExternalLink'), () => ({ useExternalLink: () => ({ staticUrls: mocks.staticUrls }) })) -vi.mock('@/platform/telemetry', () => ({ +vi.mock(import('@/platform/telemetry'), () => ({ useTelemetry: () => mocks.telemetry })) diff --git a/src/components/rightSidePanel/errors/useErrorGroups.test.ts b/src/components/rightSidePanel/errors/useErrorGroups.test.ts index db2a0766d86..3f63b507d84 100644 --- a/src/components/rightSidePanel/errors/useErrorGroups.test.ts +++ b/src/components/rightSidePanel/errors/useErrorGroups.test.ts @@ -6,7 +6,7 @@ import type { MissingNodeType } from '@/types/comfy' import type { NodeExecutionId } from '@/types/nodeIdentification' import type * as GraphTraversalUtil from '@/utils/graphTraversalUtil' -vi.mock('@/scripts/app', () => ({ +vi.mock(import('@/scripts/app'), () => ({ app: { isGraphReady: true, rootGraph: { @@ -19,7 +19,7 @@ vi.mock('@/scripts/app', () => ({ } })) -vi.mock('@/utils/graphTraversalUtil', () => ({ +vi.mock(import('@/utils/graphTraversalUtil'), () => ({ getNodeByExecutionId: vi.fn(), getExecutionIdByNode: vi.fn(), getRootParentNode: vi.fn(() => null), @@ -31,13 +31,13 @@ const mockIsCloud = vi.hoisted(() => ({ value: false })) const unknownValidationMessage = vi.hoisted( () => 'A node returned a validation error ComfyUI does not recognize.' ) -vi.mock('@/platform/distribution/types', () => ({ +vi.mock(import('@/platform/distribution/types'), () => ({ get isCloud() { return mockIsCloud.value } })) -vi.mock('@/i18n', () => { +vi.mock(import('@/i18n'), () => { const messages: Record = { 'errorCatalog.validationErrors.required_input_missing.title': 'Missing connection', @@ -109,22 +109,22 @@ vi.mock('@/i18n', () => { } }) -vi.mock('@/stores/comfyRegistryStore', () => ({ +vi.mock(import('@/stores/comfyRegistryStore'), () => ({ useComfyRegistryStore: () => ({ inferPackFromNodeName: vi.fn() }) })) -vi.mock('@/utils/nodeTitleUtil', () => ({ +vi.mock(import('@/utils/nodeTitleUtil'), () => ({ resolveNodeDisplayName: vi.fn(() => '') })) -vi.mock('@/utils/litegraphUtil', () => ({ +vi.mock(import('@/utils/litegraphUtil'), () => ({ isLGraphNode: vi.fn(() => false) })) -vi.mock( - '@/platform/missingModel/composables/useMissingModelInteractions', +vi.mock( + import('@/platform/missingModel/composables/useMissingModelInteractions'), () => ({ clearMissingModelState: vi.fn() }) diff --git a/src/components/rightSidePanel/errors/useErrorReport.test.ts b/src/components/rightSidePanel/errors/useErrorReport.test.ts index 846d546f2b9..3a20b290d77 100644 --- a/src/components/rightSidePanel/errors/useErrorReport.test.ts +++ b/src/components/rightSidePanel/errors/useErrorReport.test.ts @@ -31,13 +31,13 @@ const storeState = vi.hoisted(() => { } }) -vi.mock('@/scripts/api', () => ({ +vi.mock(import('@/scripts/api'), () => ({ api: { getLogs: mocks.getLogs } })) -vi.mock('@/scripts/app', () => ({ +vi.mock(import('@/scripts/app'), () => ({ app: { rootGraph: { serialize: mocks.serialize @@ -45,11 +45,11 @@ vi.mock('@/scripts/app', () => ({ } })) -vi.mock('@/utils/errorReportUtil', () => ({ +vi.mock(import('@/utils/errorReportUtil'), () => ({ generateErrorReport: mocks.generateErrorReport })) -vi.mock('@/stores/systemStatsStore', async () => { +vi.mock(import('@/stores/systemStatsStore'), async () => { const { ref: vueRef } = await import('vue') const systemStatsRef = vueRef(null) const isLoadingRef = vueRef(false) diff --git a/src/components/rightSidePanel/parameters/SectionWidgets.test.ts b/src/components/rightSidePanel/parameters/SectionWidgets.test.ts index afdaa493868..1a3bd88944a 100644 --- a/src/components/rightSidePanel/parameters/SectionWidgets.test.ts +++ b/src/components/rightSidePanel/parameters/SectionWidgets.test.ts @@ -32,20 +32,24 @@ const getNodeById = vi.fn() const animateToBounds = vi.fn() const selectedItems: unknown[] = [] -vi.mock('@/renderer/core/canvas/canvasStore', () => ({ - useCanvasStore: () => ({ - canvas: { setDirty, graph: { getNodeById }, animateToBounds }, - selectedItems +vi.mock( + import('@/renderer/core/canvas/canvasStore'), + + () => ({ + useCanvasStore: () => ({ + canvas: { setDirty, graph: { getNodeById }, animateToBounds }, + selectedItems + }) }) -})) +) -vi.mock('@/stores/nodeDefStore', () => ({ +vi.mock(import('@/stores/nodeDefStore'), () => ({ useNodeDefStore: () => ({ getInputSpecForWidget: mockGetInputSpecForWidget }) })) -vi.mock('@/platform/telemetry', () => ({ +vi.mock(import('@/platform/telemetry'), () => ({ useTelemetry: () => ({ trackUiButtonClicked: mockTrackUiButtonClicked }) diff --git a/src/components/rightSidePanel/parameters/TabSubgraphInputs.test.ts b/src/components/rightSidePanel/parameters/TabSubgraphInputs.test.ts index 8976300cf01..f1c20e25b70 100644 --- a/src/components/rightSidePanel/parameters/TabSubgraphInputs.test.ts +++ b/src/components/rightSidePanel/parameters/TabSubgraphInputs.test.ts @@ -16,7 +16,7 @@ import { widgetId } from '@/types/widgetId' import TabSubgraphInputs from './TabSubgraphInputs.vue' -vi.mock('@/services/litegraphService', () => ({ +vi.mock(import('@/services/litegraphService'), () => ({ useLitegraphService: () => ({ updatePreviews: vi.fn() }) })) diff --git a/src/components/rightSidePanel/parameters/WidgetActions.test.ts b/src/components/rightSidePanel/parameters/WidgetActions.test.ts index 4967ebd2448..54040cf5433 100644 --- a/src/components/rightSidePanel/parameters/WidgetActions.test.ts +++ b/src/components/rightSidePanel/parameters/WidgetActions.test.ts @@ -28,42 +28,46 @@ const { mockTrackWidgetFavoriteToggled: vi.fn() })) -vi.mock('@/core/graph/subgraph/promotionUtils', () => ({ +vi.mock(import('@/core/graph/subgraph/promotionUtils'), () => ({ promoteWidget: vi.fn() })) -vi.mock('@/stores/nodeDefStore', () => ({ +vi.mock(import('@/stores/nodeDefStore'), () => ({ useNodeDefStore: () => ({ getInputSpecForWidget: mockGetInputSpecForWidget }) })) -vi.mock('@/renderer/core/canvas/canvasStore', () => ({ - useCanvasStore: () => ({ - canvas: { setDirty: vi.fn() } +vi.mock( + import('@/renderer/core/canvas/canvasStore'), + + () => ({ + useCanvasStore: () => ({ + canvas: { setDirty: vi.fn() } + }) }) -})) +) -vi.mock('@/stores/workspace/favoritedWidgetsStore', () => ({ +vi.mock(import('@/stores/workspace/favoritedWidgetsStore'), () => ({ useFavoritedWidgetsStore: () => ({ isFavorited: mockIsFavorited, toggleFavorite: mockToggleFavorite }) })) -vi.mock('@/platform/telemetry', () => ({ +vi.mock(import('@/platform/telemetry'), () => ({ useTelemetry: () => ({ trackWidgetFavoriteToggled: mockTrackWidgetFavoriteToggled }) })) -vi.mock('@/services/dialogService', () => ({ +vi.mock(import('@/services/dialogService'), () => ({ useDialogService: () => ({ prompt: vi.fn() }) })) -vi.mock('@/components/button/MoreButton.vue', () => ({ +vi.mock(import('@/components/button/MoreButton.vue'), () => ({ default: (_: unknown, { slots }: { slots: Slots }) => h('div', slots.default?.({ close: () => {} })) })) diff --git a/src/components/rightSidePanel/parameters/WidgetItem.test.ts b/src/components/rightSidePanel/parameters/WidgetItem.test.ts index 05fc2e07c13..586f0d01e45 100644 --- a/src/components/rightSidePanel/parameters/WidgetItem.test.ts +++ b/src/components/rightSidePanel/parameters/WidgetItem.test.ts @@ -25,19 +25,23 @@ const { mockGetInputSpecForWidget, StubWidgetComponent } = vi.hoisted(() => ({ } })) -vi.mock('@/stores/nodeDefStore', () => ({ +vi.mock(import('@/stores/nodeDefStore'), () => ({ useNodeDefStore: () => ({ getInputSpecForWidget: mockGetInputSpecForWidget }) })) -vi.mock('@/renderer/core/canvas/canvasStore', () => ({ - useCanvasStore: () => ({ - canvas: { setDirty: vi.fn() } +vi.mock( + import('@/renderer/core/canvas/canvasStore'), + + () => ({ + useCanvasStore: () => ({ + canvas: { setDirty: vi.fn() } + }) }) -})) +) -vi.mock('@/stores/workspace/favoritedWidgetsStore', () => ({ +vi.mock(import('@/stores/workspace/favoritedWidgetsStore'), () => ({ useFavoritedWidgetsStore: () => ({ isFavorited: vi.fn().mockReturnValue(false), toggleFavorite: vi.fn() @@ -45,15 +49,17 @@ vi.mock('@/stores/workspace/favoritedWidgetsStore', () => ({ })) vi.mock( - '@/renderer/extensions/vueNodes/widgets/registry/widgetRegistry', + import('@/renderer/extensions/vueNodes/widgets/registry/widgetRegistry'), + () => ({ getComponent: () => StubWidgetComponent, shouldExpand: () => false }) ) -vi.mock( - '@/renderer/extensions/vueNodes/widgets/components/WidgetLegacy.vue', +vi.mock( + import('@/renderer/extensions/vueNodes/widgets/components/WidgetLegacy.vue'), + () => ({ default: StubWidgetComponent }) diff --git a/src/components/rightSidePanel/rightSidePanelTabTelemetry.test.ts b/src/components/rightSidePanel/rightSidePanelTabTelemetry.test.ts index 22444d0657d..24f7fff5df9 100644 --- a/src/components/rightSidePanel/rightSidePanelTabTelemetry.test.ts +++ b/src/components/rightSidePanel/rightSidePanelTabTelemetry.test.ts @@ -4,7 +4,7 @@ const { mockTrackUiButtonClicked } = vi.hoisted(() => ({ mockTrackUiButtonClicked: vi.fn() })) -vi.mock('@/platform/telemetry', () => ({ +vi.mock(import('@/platform/telemetry'), () => ({ useTelemetry: () => ({ trackUiButtonClicked: mockTrackUiButtonClicked }) diff --git a/src/components/rightSidePanel/subgraph/SubgraphEditor.test.ts b/src/components/rightSidePanel/subgraph/SubgraphEditor.test.ts index e79c7b7d78b..4b276400ca5 100644 --- a/src/components/rightSidePanel/subgraph/SubgraphEditor.test.ts +++ b/src/components/rightSidePanel/subgraph/SubgraphEditor.test.ts @@ -23,7 +23,7 @@ type DraggableListProps = ComponentProps type PromotedRow = DraggableListProps['modelValue'] extends Array ? T : never -vi.mock('@/services/litegraphService', () => ({ +vi.mock(import('@/services/litegraphService'), () => ({ useLitegraphService: () => ({ updatePreviews: vi.fn() }) })) diff --git a/src/components/searchbox/NodeSearchBoxPopover.test.ts b/src/components/searchbox/NodeSearchBoxPopover.test.ts index d237ec46b9f..610af644fb1 100644 --- a/src/components/searchbox/NodeSearchBoxPopover.test.ts +++ b/src/components/searchbox/NodeSearchBoxPopover.test.ts @@ -18,7 +18,7 @@ const { addNodeOnGraph } = vi.hoisted(() => ({ addNodeOnGraph: vi.fn() })) -vi.mock('@/services/litegraphService', () => ({ +vi.mock(import('@/services/litegraphService'), () => ({ useLitegraphService: () => ({ getCanvasCenter: vi.fn(() => [0, 0]), addNodeOnGraph diff --git a/src/components/searchbox/v2/NodeSearchInput.test.ts b/src/components/searchbox/v2/NodeSearchInput.test.ts index 71a85a487e5..8ef92c185a4 100644 --- a/src/components/searchbox/v2/NodeSearchInput.test.ts +++ b/src/components/searchbox/v2/NodeSearchInput.test.ts @@ -10,13 +10,13 @@ import { import type { ComfyNodeDefImpl } from '@/stores/nodeDefStore' import type { FuseFilter, FuseFilterWithValue } from '@/utils/fuseUtil' -vi.mock('@/utils/litegraphUtil', () => ({ +vi.mock(import('@/utils/litegraphUtil'), () => ({ getLinkTypeColor: vi.fn((type: string) => type === 'IMAGE' ? '#64b5f6' : undefined ) })) -vi.mock('@/platform/settings/settingStore', () => ({ +vi.mock(import('@/platform/settings/settingStore'), () => ({ useSettingStore: vi.fn(() => ({ get: vi.fn((key: string) => { if (key === 'Comfy.NodeLibrary.Bookmarks.V2') return [] diff --git a/src/components/sidebar/SideToolbar.test.ts b/src/components/sidebar/SideToolbar.test.ts index 080711cb9f6..aac33b99f0d 100644 --- a/src/components/sidebar/SideToolbar.test.ts +++ b/src/components/sidebar/SideToolbar.test.ts @@ -26,20 +26,20 @@ const state = vi.hoisted(() => ({ activeSidebarTab: null as { id: string } | null })) -vi.mock('@/platform/distribution/types', () => ({ +vi.mock(import('@/platform/distribution/types'), () => ({ isCloud: false, isDesktop: false, isNightly: false })) -vi.mock('@/stores/workspaceStore', () => ({ +vi.mock(import('@/stores/workspaceStore'), () => ({ useWorkspaceStore: () => ({ getSidebarTabs: () => state.sidebarTabs, sidebarTab: { activeSidebarTab: state.activeSidebarTab } }) })) -vi.mock('@/platform/settings/settingStore', () => ({ +vi.mock(import('@/platform/settings/settingStore'), () => ({ useSettingStore: () => ({ get: (key: string) => { if (key === 'Comfy.Sidebar.Size') return 'large' @@ -49,11 +49,11 @@ vi.mock('@/platform/settings/settingStore', () => ({ }) })) -vi.mock('@/stores/userStore', () => ({ +vi.mock(import('@/stores/userStore'), () => ({ useUserStore: () => ({ isMultiUserServer: state.isMultiUserServer }) })) -vi.mock('@/stores/commandStore', () => ({ +vi.mock(import('@/stores/commandStore'), () => ({ useCommandStore: () => ({ commands: [ { id: 'Workspace.ToggleSidebarTab.assets', function: spies.toggleAssets } @@ -61,15 +61,19 @@ vi.mock('@/stores/commandStore', () => ({ }) })) -vi.mock('@/renderer/core/canvas/canvasStore', () => ({ - useCanvasStore: () => ({ canvas: null }) -})) +vi.mock( + import('@/renderer/core/canvas/canvasStore'), + + () => ({ + useCanvasStore: () => ({ canvas: null }) + }) +) -vi.mock('@/platform/keybindings/keybindingStore', () => ({ +vi.mock(import('@/platform/keybindings/keybindingStore'), () => ({ useKeybindingStore: () => ({ getKeybindingByCommandId: () => undefined }) })) -vi.mock('@/platform/telemetry', () => ({ +vi.mock(import('@/platform/telemetry'), () => ({ useTelemetry: () => ({ trackUiButtonClicked: spies.trackUiButtonClicked }) })) diff --git a/src/components/sidebar/SidebarHelpCenterIcon.test.ts b/src/components/sidebar/SidebarHelpCenterIcon.test.ts index 9db03aebcd4..6b5563a4bd6 100644 --- a/src/components/sidebar/SidebarHelpCenterIcon.test.ts +++ b/src/components/sidebar/SidebarHelpCenterIcon.test.ts @@ -16,7 +16,7 @@ const canvasState = vi.hoisted(() => ({ linearMode: true })) const helpCenterSpies = vi.hoisted(() => ({ toggleHelpCenter: vi.fn() })) -vi.mock('@/platform/surveys/useTypeformEmbed', async () => { +vi.mock(import('@/platform/surveys/useTypeformEmbed'), async () => { const { computed } = await import('vue') return { useTypeformEmbed: (containerRef: unknown, formId: string) => { @@ -31,7 +31,7 @@ vi.mock('@/platform/surveys/useTypeformEmbed', async () => { } }) -vi.mock('@/composables/useHelpCenter', async () => { +vi.mock(import('@/composables/useHelpCenter'), async () => { const { ref } = await import('vue') return { useHelpCenter: () => ({ @@ -41,17 +41,21 @@ vi.mock('@/composables/useHelpCenter', async () => { } }) -vi.mock('@/platform/settings/settingStore', () => ({ +vi.mock(import('@/platform/settings/settingStore'), () => ({ useSettingStore: () => ({ get: () => 'left' }) })) -vi.mock('@/renderer/core/canvas/canvasStore', async () => { - const { computed, reactive } = await import('vue') - return { - useCanvasStore: () => - reactive({ linearMode: computed(() => canvasState.linearMode) }) +vi.mock( + import('@/renderer/core/canvas/canvasStore'), + + async () => { + const { computed, reactive } = await import('vue') + return { + useCanvasStore: () => + reactive({ linearMode: computed(() => canvasState.linearMode) }) + } } -}) +) const FEEDBACK_LOAD_ERROR = 'Failed to load feedback form. Please try again later.' diff --git a/src/components/sidebar/tabs/AppsSidebarTab.test.ts b/src/components/sidebar/tabs/AppsSidebarTab.test.ts index 0c5909fad64..9bfc92636b8 100644 --- a/src/components/sidebar/tabs/AppsSidebarTab.test.ts +++ b/src/components/sidebar/tabs/AppsSidebarTab.test.ts @@ -13,50 +13,59 @@ const workflowStoreState = vi.hoisted(() => ({ persistedWorkflows: [] as ComfyWorkflow[] })) -vi.mock('@/stores/commandStore', () => ({ +vi.mock(import('@/stores/commandStore'), () => ({ useCommandStore: () => ({ execute }) })) -vi.mock('@/platform/workflow/management/stores/workflowStore', async () => { - const { ComfyWorkflow } = - await import('@/platform/workflow/management/stores/comfyWorkflow') - return { - ComfyWorkflow, - useWorkflowStore: () => ({ - get workflows() { - return workflowStoreState.persistedWorkflows - }, - get persistedWorkflows() { - return workflowStoreState.persistedWorkflows - }, - bookmarkedWorkflows: [], - openWorkflows: [], - activeWorkflow: undefined, - isSyncLoading: false, - syncWorkflows: vi.fn() - }), - useWorkflowBookmarkStore: () => ({ loadBookmarks: vi.fn() }) +vi.mock( + import('@/platform/workflow/management/stores/workflowStore'), + async () => { + const { ComfyWorkflow } = + await import('@/platform/workflow/management/stores/comfyWorkflow') + return { + ComfyWorkflow, + useWorkflowStore: () => ({ + get workflows() { + return workflowStoreState.persistedWorkflows + }, + get persistedWorkflows() { + return workflowStoreState.persistedWorkflows + }, + bookmarkedWorkflows: [], + openWorkflows: [], + activeWorkflow: undefined, + isSyncLoading: false, + syncWorkflows: vi.fn() + }), + useWorkflowBookmarkStore: () => ({ loadBookmarks: vi.fn() }) + } } -}) +) -vi.mock('@/platform/workflow/core/services/workflowService', () => ({ - useWorkflowService: () => ({}) -})) +vi.mock( + import('@/platform/workflow/core/services/workflowService'), + () => ({ + useWorkflowService: () => ({}) + }) +) -vi.mock('@/platform/telemetry/searchQuery/useSearchQueryTracking', () => ({ - useSearchQueryTracking: () => undefined -})) +vi.mock( + import('@/platform/telemetry/searchQuery/useSearchQueryTracking'), + () => ({ + useSearchQueryTracking: () => undefined + }) +) -vi.mock('@/stores/workspaceStore', () => ({ +vi.mock(import('@/stores/workspaceStore'), () => ({ useWorkspaceStore: () => ({ shiftDown: false }) })) -vi.mock('@/composables/useAppMode', async () => { +vi.mock(import('@/composables/useAppMode'), async () => { const { computed } = await import('vue') return { useAppMode: () => ({ isAppMode: computed(() => true) }) } }) -vi.mock('@/platform/settings/settingStore', () => ({ +vi.mock(import('@/platform/settings/settingStore'), () => ({ useSettingStore: () => ({ get: () => undefined }) })) diff --git a/src/components/sidebar/tabs/AssetsSidebarListView.test.ts b/src/components/sidebar/tabs/AssetsSidebarListView.test.ts index 7f26fd02da0..1c6c23a7e70 100644 --- a/src/components/sidebar/tabs/AssetsSidebarListView.test.ts +++ b/src/components/sidebar/tabs/AssetsSidebarListView.test.ts @@ -3,19 +3,21 @@ import { fromPartial } from '@total-typescript/shoehorn' import { render, fireEvent } from '@testing-library/vue' import { defineComponent } from 'vue' import { describe, expect, it, vi } from 'vitest' +import { createI18n } from 'vue-i18n' +import enMessages from '@/locales/en/main.json' with { type: 'json' } import type { OutputStackListItem } from '@/platform/assets/composables/useOutputStacks' import type { AssetItem } from '@/platform/assets/schemas/assetSchema' import AssetsSidebarListView from './AssetsSidebarListView.vue' -vi.mock('vue-i18n', () => ({ - useI18n: () => ({ - t: (key: string) => key - }) -})) +const i18n = createI18n({ + legacy: false, + locale: 'en', + messages: { en: enMessages } +}) -vi.mock('@/stores/assetsStore', () => ({ +vi.mock(import('@/stores/assetsStore'), () => ({ useAssetsStore: () => ({ isAssetDeleting: () => false }) @@ -85,6 +87,7 @@ function renderListView( ...props }, global: { + plugins: [i18n], stubs: { VirtualGrid: VirtualGridStub, AssetsListItem: AssetsListItemStub diff --git a/src/components/sidebar/tabs/AssetsSidebarTab.test.ts b/src/components/sidebar/tabs/AssetsSidebarTab.test.ts index d820b777c26..90ff25f0a04 100644 --- a/src/components/sidebar/tabs/AssetsSidebarTab.test.ts +++ b/src/components/sidebar/tabs/AssetsSidebarTab.test.ts @@ -27,7 +27,7 @@ const outputAssetState = vi.hoisted(() => ({ hasMore: false })) -vi.mock('@/stores/assetsStore', async () => { +vi.mock(import('@/stores/assetsStore'), async () => { const { ref } = await import('vue') const store = { @@ -58,50 +58,62 @@ vi.mock('@/stores/assetsStore', async () => { } }) -vi.mock('@/platform/assets/composables/useAssetGridSelection', async () => { - const { ref } = await import('vue') - return { - useAssetGridSelection: () => ({ marqueeStyle: ref(null) }) +vi.mock( + import('@/platform/assets/composables/useAssetGridSelection'), + async () => { + const { ref } = await import('vue') + return { + useAssetGridSelection: () => ({ marqueeStyle: ref(null) }) + } } -}) - -vi.mock('@/platform/assets/composables/useAssetSelection', async () => { - const { ref } = await import('vue') - - return { - useAssetSelection: () => ({ - isSelected: vi.fn(() => false), - selectedIds: ref(new Set()), - handleAssetClick: vi.fn(), - selectAll: vi.fn(), - setSelectedIds: vi.fn(), - hasSelection: ref(false), - clearSelection: vi.fn(), - getSelectedAssets: vi.fn(() => []), - reconcileSelection: vi.fn(), - getOutputCount: vi.fn(() => 2), - getTotalOutputCount: vi.fn(() => 0), - activate: vi.fn(), - deactivate: vi.fn() - }) +) + +vi.mock( + import('@/platform/assets/composables/useAssetSelection'), + async () => { + const { ref } = await import('vue') + + return { + useAssetSelection: () => ({ + isSelected: vi.fn(() => false), + selectedIds: ref(new Set()), + handleAssetClick: vi.fn(), + selectAll: vi.fn(), + setSelectedIds: vi.fn(), + hasSelection: ref(false), + clearSelection: vi.fn(), + getSelectedAssets: vi.fn(() => []), + reconcileSelection: vi.fn(), + getOutputCount: vi.fn(() => 2), + getTotalOutputCount: vi.fn(() => 0), + activate: vi.fn(), + deactivate: vi.fn() + }) + } } -}) - -vi.mock('@/platform/assets/composables/useMediaAssetActions', () => ({ - useMediaAssetActions: () => ({ - downloadAssets: vi.fn(), - deleteAssets: vi.fn(), - addMultipleToWorkflow: vi.fn(), - openMultipleWorkflows: vi.fn(), - exportMultipleWorkflows: vi.fn() +) + +vi.mock( + import('@/platform/assets/composables/useMediaAssetActions'), + () => ({ + useMediaAssetActions: () => ({ + downloadAssets: vi.fn(), + deleteAssets: vi.fn(), + addMultipleToWorkflow: vi.fn(), + openMultipleWorkflows: vi.fn(), + exportMultipleWorkflows: vi.fn() + }) }) -})) +) -vi.mock('@/platform/assets/utils/outputAssetUtil') +vi.mock(import('@/platform/assets/utils/outputAssetUtil')) -vi.mock('primevue/usetoast', () => ({ - useToast: () => ({ add: vi.fn() }) -})) +vi.mock( + import('primevue/usetoast'), // eslint-disable-line primevue-removal/no-imports + () => ({ + useToast: () => ({ add: vi.fn() }) + }) +) const i18n = createI18n({ legacy: false, diff --git a/src/components/sidebar/tabs/BaseWorkflowsSidebarTab.test.ts b/src/components/sidebar/tabs/BaseWorkflowsSidebarTab.test.ts index b0514242a76..af790a50e51 100644 --- a/src/components/sidebar/tabs/BaseWorkflowsSidebarTab.test.ts +++ b/src/components/sidebar/tabs/BaseWorkflowsSidebarTab.test.ts @@ -77,45 +77,54 @@ const { const mockWorkflowStore = reactive(mockWorkflowStoreState) -vi.mock('@/components/common/NoResultsPlaceholder.vue', () => ({ - default: { name: 'NoResultsPlaceholder', template: '
' } -})) - -vi.mock('@/components/ui/search-input/SearchInput.vue', () => ({ - default: { - name: 'SearchInput', - template: '
', - props: ['modelValue', 'placeholder'], - setup( - _props: { modelValue: string; placeholder?: string }, - { - emit, - expose - }: { - emit: (event: 'update:modelValue' | 'search', value: string) => void - expose: (value: { focus: () => void }) => void +vi.mock( + import('@/components/common/NoResultsPlaceholder.vue'), + () => ({ + default: { name: 'NoResultsPlaceholder', template: '
' } + }) +) + +vi.mock( + import('@/components/ui/search-input/SearchInput.vue'), + () => ({ + default: { + name: 'SearchInput', + template: '
', + props: ['modelValue', 'placeholder'], + setup( + _props: { modelValue: string; placeholder?: string }, + { + emit, + expose + }: { + emit: (event: 'update:modelValue' | 'search', value: string) => void + expose: (value: { focus: () => void }) => void + } + ) { + const focus = vi.fn() + expose({ focus }) + registerSearchHandlers( + (query: string) => emit('update:modelValue', query), + (query: string) => emit('search', query) + ) + return {} } - ) { - const focus = vi.fn() - expose({ focus }) - registerSearchHandlers( - (query: string) => emit('update:modelValue', query), - (query: string) => emit('search', query) - ) - return {} } - } -})) + }) +) -vi.mock('@/components/sidebar/tabs/SidebarTopArea.vue', () => ({ - default: { name: 'SidebarTopArea', template: '
' } -})) +vi.mock( + import('@/components/sidebar/tabs/SidebarTopArea.vue'), + () => ({ + default: { name: 'SidebarTopArea', template: '
' } + }) +) -vi.mock('@/components/common/TextDivider.vue', () => ({ +vi.mock(import('@/components/common/TextDivider.vue'), () => ({ default: { name: 'TextDivider', template: '
' } })) -vi.mock('@/components/common/TreeExplorer.vue', () => ({ +vi.mock(import('@/components/common/TreeExplorer.vue'), () => ({ default: { name: 'TreeExplorer', template: '
', @@ -133,43 +142,52 @@ vi.mock('@/components/common/TreeExplorer.vue', () => ({ } })) -vi.mock('@/components/common/TreeExplorerTreeNode.vue', () => ({ - default: { - name: 'TreeExplorerTreeNode', - template: - '
', - props: ['node'] - } -})) - -vi.mock('@/components/sidebar/tabs/SidebarTabTemplate.vue', () => ({ - default: { - name: 'SidebarTabTemplate', - template: - '
' - } -})) +vi.mock( + import('@/components/common/TreeExplorerTreeNode.vue'), + () => ({ + default: { + name: 'TreeExplorerTreeNode', + template: + '
', + props: ['node'] + } + }) +) + +vi.mock( + import('@/components/sidebar/tabs/SidebarTabTemplate.vue'), + () => ({ + default: { + name: 'SidebarTabTemplate', + template: + '
' + } + }) +) -vi.mock('@/components/sidebar/tabs/workflows/WorkflowTreeLeaf.vue', () => ({ - default: { name: 'WorkflowTreeLeaf', template: '
', props: ['node'] } -})) +vi.mock( + import('@/components/sidebar/tabs/workflows/WorkflowTreeLeaf.vue'), + () => ({ + default: { name: 'WorkflowTreeLeaf', template: '
', props: ['node'] } + }) +) -vi.mock('@/components/ui/button/Button.vue', () => ({ +vi.mock(import('@/components/ui/button/Button.vue'), () => ({ default: { name: 'Button', template: '' } })) -vi.mock('@/composables/useTreeExpansion', () => ({ +vi.mock(import('@/composables/useTreeExpansion'), () => ({ useTreeExpansion: () => ({ expandNode: mockExpandNode, toggleNodeOnEvent: mockToggleNodeOnEvent }) })) -vi.mock('@/composables/useAppMode', () => ({ +vi.mock(import('@/composables/useAppMode'), () => ({ useAppMode: () => ({ isAppMode: ref(false) }) })) -vi.mock('@/platform/settings/settingStore', () => ({ +vi.mock(import('@/platform/settings/settingStore'), () => ({ useSettingStore: () => ({ get: vi.fn((key: string) => { if (key === 'Comfy.Workflow.WorkflowTabsPosition') return 'Sidebar' @@ -178,21 +196,27 @@ vi.mock('@/platform/settings/settingStore', () => ({ }) })) -vi.mock('@/platform/workflow/core/services/workflowService', () => ({ - useWorkflowService: () => mockWorkflowService -})) +vi.mock( + import('@/platform/workflow/core/services/workflowService'), + () => ({ + useWorkflowService: () => mockWorkflowService + }) +) -vi.mock('@/stores/workspaceStore', () => ({ +vi.mock(import('@/stores/workspaceStore'), () => ({ useWorkspaceStore: () => ({ shiftDown: false }) })) -vi.mock('@/platform/workflow/management/stores/workflowStore', () => ({ - useWorkflowStore: () => mockWorkflowStore, - useWorkflowBookmarkStore: () => ({ loadBookmarks: mockLoadBookmarks }), - ComfyWorkflow: class { - static basePath = 'workflows/' - } -})) +vi.mock( + import('@/platform/workflow/management/stores/workflowStore'), + () => ({ + useWorkflowStore: () => mockWorkflowStore, + useWorkflowBookmarkStore: () => ({ loadBookmarks: mockLoadBookmarks }), + ComfyWorkflow: class { + static basePath = 'workflows/' + } + }) +) const i18n = createI18n({ legacy: false, diff --git a/src/components/sidebar/tabs/ModelLibrarySidebarTab.test.ts b/src/components/sidebar/tabs/ModelLibrarySidebarTab.test.ts index 0640f051dce..2083d98e7aa 100644 --- a/src/components/sidebar/tabs/ModelLibrarySidebarTab.test.ts +++ b/src/components/sidebar/tabs/ModelLibrarySidebarTab.test.ts @@ -54,16 +54,16 @@ const { } }) -vi.mock('@/composables/node/useNodeDragToCanvas', () => ({ +vi.mock(import('@/composables/node/useNodeDragToCanvas'), () => ({ useNodeDragToCanvas: () => ({ startDrag: mockStartDrag }) })) const mockToastAdd = vi.hoisted(() => vi.fn()) -vi.mock('@/platform/updates/common/toastStore', () => ({ +vi.mock(import('@/platform/updates/common/toastStore'), () => ({ useToastStore: () => ({ add: mockToastAdd }) })) -vi.mock('@/stores/modelToNodeStore', () => ({ +vi.mock(import('@/stores/modelToNodeStore'), () => ({ useModelToNodeStore: () => ({ getNodeProvider: mockGetNodeProvider }) })) @@ -76,7 +76,7 @@ const mockModel = fromPartial({ searchable: 'checkpoints/model.safetensors' }) -vi.mock('@/stores/modelStore', async () => { +vi.mock(import('@/stores/modelStore'), async () => { const { reactive } = await import('vue') const models = reactive([]) modelsState.push = (model: unknown) => { @@ -103,7 +103,7 @@ vi.mock('@/stores/modelStore', async () => { } }) -vi.mock('@/stores/assetDownloadStore', async () => { +vi.mock(import('@/stores/assetDownloadStore'), async () => { const { ref } = await import('vue') const lastCompletedDownload = ref<{ taskId: string @@ -122,7 +122,7 @@ vi.mock('@/stores/assetDownloadStore', async () => { } }) -vi.mock('@/platform/settings/settingStore', () => ({ +vi.mock(import('@/platform/settings/settingStore'), () => ({ useSettingStore: () => ({ get: vi.fn((key: string) => { if (key === 'Comfy.ModelLibrary.NameFormat') return 'filename' @@ -136,14 +136,14 @@ vi.mock('@/platform/settings/settingStore', () => ({ })) const mockExpandNode = vi.hoisted(() => vi.fn()) -vi.mock('@/composables/useTreeExpansion', () => ({ +vi.mock(import('@/composables/useTreeExpansion'), () => ({ useTreeExpansion: () => ({ expandNode: mockExpandNode, toggleNodeOnEvent: mockToggleNodeOnEvent }) })) -vi.mock('@/components/common/TreeExplorer.vue', async () => { +vi.mock(import('@/components/common/TreeExplorer.vue'), async () => { const { watchEffect } = await import('vue') return { default: { @@ -163,47 +163,50 @@ vi.mock('@/components/common/TreeExplorer.vue', async () => { } }) -vi.mock('@/components/ui/search-input/SearchInput.vue', () => ({ - default: { - name: 'SearchInput', - template: - '' + - '', - props: ['modelValue', 'placeholder'], - emits: ['update:modelValue', 'search'], - setup( - _props: unknown, - { - emit, - expose - }: { - emit: (event: 'update:modelValue' | 'search', value: string) => void - expose: (exposed: Record) => void - } - ) { - expose({ focus: vi.fn() }) - return { - onInput: (event: Event) => { - const value = (event.target as HTMLInputElement).value - emit('update:modelValue', value) - emit('search', value) - }, - // A keystroke the real SearchInput has not yet debounced into a - // `search` emit: only the model value updates. - onRawInput: (event: Event) => { - const value = (event.target as HTMLInputElement).value - emit('update:modelValue', value) +vi.mock( + import('@/components/ui/search-input/SearchInput.vue'), + () => ({ + default: { + name: 'SearchInput', + template: + '' + + '', + props: ['modelValue', 'placeholder'], + emits: ['update:modelValue', 'search'], + setup( + _props: unknown, + { + emit, + expose + }: { + emit: (event: 'update:modelValue' | 'search', value: string) => void + expose: (exposed: Record) => void + } + ) { + expose({ focus: vi.fn() }) + return { + onInput: (event: Event) => { + const value = (event.target as HTMLInputElement).value + emit('update:modelValue', value) + emit('search', value) + }, + // A keystroke the real SearchInput has not yet debounced into a + // `search` emit: only the model value updates. + onRawInput: (event: Event) => { + const value = (event.target as HTMLInputElement).value + emit('update:modelValue', value) + } } } } - } -})) + }) +) -vi.mock('./SidebarTopArea.vue', () => ({ +vi.mock(import('./SidebarTopArea.vue'), () => ({ default: { name: 'SidebarTopArea', template: '
' } })) -vi.mock('./SidebarTabTemplate.vue', () => ({ +vi.mock(import('./SidebarTabTemplate.vue'), () => ({ default: { name: 'SidebarTabTemplate', template: @@ -211,11 +214,11 @@ vi.mock('./SidebarTabTemplate.vue', () => ({ } })) -vi.mock('./modelLibrary/ElectronDownloadItems.vue', () => ({ +vi.mock(import('./modelLibrary/ElectronDownloadItems.vue'), () => ({ default: { name: 'ElectronDownloadItems', template: '
' } })) -vi.mock('./modelLibrary/ModelTreeLeaf.vue', () => ({ +vi.mock(import('./modelLibrary/ModelTreeLeaf.vue'), () => ({ default: { name: 'ModelTreeLeaf', template: '
', props: ['node'] } })) diff --git a/src/components/sidebar/tabs/NodeLibrarySidebarTab.test.ts b/src/components/sidebar/tabs/NodeLibrarySidebarTab.test.ts index cc38bb6ab9d..a2c08cc5b86 100644 --- a/src/components/sidebar/tabs/NodeLibrarySidebarTab.test.ts +++ b/src/components/sidebar/tabs/NodeLibrarySidebarTab.test.ts @@ -43,11 +43,11 @@ const { } }) -vi.mock('@/services/litegraphService', () => ({ +vi.mock(import('@/services/litegraphService'), () => ({ useLitegraphService: () => ({ addNodeOnGraph: mockAddNodeOnGraph }) })) -vi.mock('@/services/nodeOrganizationService', () => ({ +vi.mock(import('@/services/nodeOrganizationService'), () => ({ DEFAULT_GROUPING_ID: 'group', DEFAULT_SORTING_ID: 'sort', nodeOrganizationService: { @@ -59,14 +59,14 @@ vi.mock('@/services/nodeOrganizationService', () => ({ } })) -vi.mock('@/composables/useTreeExpansion', () => ({ +vi.mock(import('@/composables/useTreeExpansion'), () => ({ useTreeExpansion: () => ({ expandNode: vi.fn(), toggleNodeOnEvent: mockToggleNodeOnEvent }) })) -vi.mock('@/components/common/TreeExplorer.vue', () => ({ +vi.mock(import('@/components/common/TreeExplorer.vue'), () => ({ default: { name: 'TreeExplorer', template: '
', @@ -77,19 +77,22 @@ vi.mock('@/components/common/TreeExplorer.vue', () => ({ } })) -vi.mock('@/components/ui/search-input/SearchInput.vue', () => ({ - default: { - name: 'SearchInput', - template: '', - props: ['modelValue', 'placeholder'], - setup() { - return { focus: vi.fn() } - }, - expose: ['focus'] - } -})) +vi.mock( + import('@/components/ui/search-input/SearchInput.vue'), + () => ({ + default: { + name: 'SearchInput', + template: '', + props: ['modelValue', 'placeholder'], + setup() { + return { focus: vi.fn() } + }, + expose: ['focus'] + } + }) +) -vi.mock('./nodeLibrary/NodeBookmarkTreeExplorer.vue', () => ({ +vi.mock(import('./nodeLibrary/NodeBookmarkTreeExplorer.vue'), () => ({ default: { name: 'NodeBookmarkTreeExplorer', template: '
', @@ -97,14 +100,14 @@ vi.mock('./nodeLibrary/NodeBookmarkTreeExplorer.vue', () => ({ } })) -vi.mock('./SidebarTabTemplate.vue', () => ({ +vi.mock(import('./SidebarTabTemplate.vue'), () => ({ default: { name: 'SidebarTabTemplate', template: '
' } })) -vi.mock('@/components/common/SearchFilterChip.vue', () => ({ +vi.mock(import('@/components/common/SearchFilterChip.vue'), () => ({ default: { name: 'SearchFilterChip', template: @@ -113,7 +116,7 @@ vi.mock('@/components/common/SearchFilterChip.vue', () => ({ } })) -vi.mock('@/components/searchbox/NodeSearchFilter.vue', () => ({ +vi.mock(import('@/components/searchbox/NodeSearchFilter.vue'), () => ({ default: { name: 'NodeSearchFilter', template: @@ -121,13 +124,16 @@ vi.mock('@/components/searchbox/NodeSearchFilter.vue', () => ({ } })) -vi.mock('primevue/popover', () => ({ - default: { - name: 'Popover', - template: '
', - methods: { toggle: vi.fn(), hide: vi.fn() } - } -})) +vi.mock( + import('primevue/popover'), // eslint-disable-line primevue-removal/no-imports + () => ({ + default: { + name: 'Popover', + template: '
', + methods: { toggle: vi.fn(), hide: vi.fn() } + } + }) +) const i18n = createI18n({ legacy: false, diff --git a/src/components/sidebar/tabs/NodeLibrarySidebarTabV2.test.ts b/src/components/sidebar/tabs/NodeLibrarySidebarTabV2.test.ts index 47155d39bed..afc76479a1f 100644 --- a/src/components/sidebar/tabs/NodeLibrarySidebarTabV2.test.ts +++ b/src/components/sidebar/tabs/NodeLibrarySidebarTabV2.test.ts @@ -11,13 +11,13 @@ const hoisted = vi.hoisted(() => ({ mockSearchNode: vi.fn<(query: string) => unknown[]>(() => []) })) -vi.mock('@/services/nodeSearchService', () => ({ +vi.mock(import('@/services/nodeSearchService'), () => ({ NodeSearchService: class { searchNode = hoisted.mockSearchNode } })) -vi.mock('@vueuse/core', async () => { +vi.mock(import('@vueuse/core'), async () => { const actual = await vi.importActual('@vueuse/core') return { ...actual, @@ -27,7 +27,7 @@ vi.mock('@vueuse/core', async () => { } }) -vi.mock('@/composables/node/useNodeDragToCanvas', () => ({ +vi.mock(import('@/composables/node/useNodeDragToCanvas'), () => ({ useNodeDragToCanvas: () => ({ isDragging: { value: false }, draggedNode: { value: null }, @@ -36,7 +36,7 @@ vi.mock('@/composables/node/useNodeDragToCanvas', () => ({ }) })) -vi.mock('@/services/nodeOrganizationService', () => ({ +vi.mock(import('@/services/nodeOrganizationService'), () => ({ DEFAULT_TAB_ID: 'essentials', DEFAULT_SORTING_ID: 'alphabetical', nodeOrganizationService: { @@ -45,7 +45,7 @@ vi.mock('@/services/nodeOrganizationService', () => ({ } })) -vi.mock('./nodeLibrary/AllNodesPanel.vue', () => ({ +vi.mock(import('./nodeLibrary/AllNodesPanel.vue'), () => ({ default: { name: 'AllNodesPanel', template: '
', @@ -53,7 +53,7 @@ vi.mock('./nodeLibrary/AllNodesPanel.vue', () => ({ } })) -vi.mock('./nodeLibrary/EssentialNodesPanel.vue', () => ({ +vi.mock(import('./nodeLibrary/EssentialNodesPanel.vue'), () => ({ default: { name: 'EssentialNodesPanel', template: '
', @@ -61,19 +61,22 @@ vi.mock('./nodeLibrary/EssentialNodesPanel.vue', () => ({ } })) -vi.mock('@/components/ui/search-input/SearchInput.vue', () => ({ - default: { - name: 'SearchBox', - template: - '', - props: ['modelValue', 'placeholder'], - emits: ['update:modelValue', 'search'], - setup() { - return { focus: vi.fn() } - }, - expose: ['focus'] - } -})) +vi.mock( + import('@/components/ui/search-input/SearchInput.vue'), + () => ({ + default: { + name: 'SearchBox', + template: + '', + props: ['modelValue', 'placeholder'], + emits: ['update:modelValue', 'search'], + setup() { + return { focus: vi.fn() } + }, + expose: ['focus'] + } + }) +) const i18n = createI18n({ legacy: false, diff --git a/src/components/sidebar/tabs/nodeLibrary/EssentialNodeCard.test.ts b/src/components/sidebar/tabs/nodeLibrary/EssentialNodeCard.test.ts index 4013bc4ad16..ef365bf6ec7 100644 --- a/src/components/sidebar/tabs/nodeLibrary/EssentialNodeCard.test.ts +++ b/src/components/sidebar/tabs/nodeLibrary/EssentialNodeCard.test.ts @@ -9,7 +9,7 @@ import { useNodeDefStore } from '@/stores/nodeDefStore' import EssentialNodeCard from './EssentialNodeCard.vue' -vi.mock('@/platform/settings/settingStore', () => ({ +vi.mock(import('@/platform/settings/settingStore'), () => ({ useSettingStore: () => ({ get: vi.fn().mockReturnValue('left') }) @@ -20,14 +20,14 @@ const { mockStartDrag, mockHandleNativeDrop } = vi.hoisted(() => ({ mockHandleNativeDrop: vi.fn() })) -vi.mock('@/composables/node/useNodeDragToCanvas', () => ({ +vi.mock(import('@/composables/node/useNodeDragToCanvas'), () => ({ useNodeDragToCanvas: () => ({ startDrag: mockStartDrag, handleNativeDrop: mockHandleNativeDrop }) })) -vi.mock('@/components/node/NodePreviewCard.vue', () => ({ +vi.mock(import('@/components/node/NodePreviewCard.vue'), () => ({ default: { template: '
' } diff --git a/src/components/sidebar/tabs/nodeLibrary/EssentialNodesPanel.test.ts b/src/components/sidebar/tabs/nodeLibrary/EssentialNodesPanel.test.ts index 87ddbfe7788..8cf894a6ab1 100644 --- a/src/components/sidebar/tabs/nodeLibrary/EssentialNodesPanel.test.ts +++ b/src/components/sidebar/tabs/nodeLibrary/EssentialNodesPanel.test.ts @@ -8,7 +8,7 @@ import { i18n } from '@/i18n' import EssentialNodesPanel from './EssentialNodesPanel.vue' -vi.mock('./EssentialNodeCard.vue', () => ({ +vi.mock(import('./EssentialNodeCard.vue'), () => ({ default: { props: ['tile', 'previewPanel'], template: '
{{ tile.nodeName }}
' diff --git a/src/components/sidebar/tabs/nodeLibrary/NodeBookmarkTreeExplorer.test.ts b/src/components/sidebar/tabs/nodeLibrary/NodeBookmarkTreeExplorer.test.ts index a6f973581f3..9d5d601a14a 100644 --- a/src/components/sidebar/tabs/nodeLibrary/NodeBookmarkTreeExplorer.test.ts +++ b/src/components/sidebar/tabs/nodeLibrary/NodeBookmarkTreeExplorer.test.ts @@ -80,7 +80,7 @@ const mockBookmarkedRoot: TreeNode = { ] } -vi.mock('@/stores/nodeBookmarkStore', () => ({ +vi.mock(import('@/stores/nodeBookmarkStore'), () => ({ useNodeBookmarkStore: () => ({ bookmarks: [], bookmarkedRoot: mockBookmarkedRoot, @@ -97,18 +97,18 @@ vi.mock('@/stores/nodeBookmarkStore', () => ({ }) })) -vi.mock('@/services/litegraphService', () => ({ +vi.mock(import('@/services/litegraphService'), () => ({ useLitegraphService: () => ({ addNodeOnGraph: mockAddNodeOnGraph }) })) -vi.mock('@/composables/useTreeExpansion', () => ({ +vi.mock(import('@/composables/useTreeExpansion'), () => ({ useTreeExpansion: () => ({ expandNode: vi.fn(), toggleNodeOnEvent: mockToggleNodeOnEvent }) })) -vi.mock('@/components/common/TreeExplorer.vue', () => ({ +vi.mock(import('@/components/common/TreeExplorer.vue'), () => ({ default: { name: 'TreeExplorer', template: '
', @@ -119,7 +119,7 @@ vi.mock('@/components/common/TreeExplorer.vue', () => ({ } })) -vi.mock('@/components/common/CustomizationDialog.vue', () => ({ +vi.mock(import('@/components/common/CustomizationDialog.vue'), () => ({ default: { name: 'FolderCustomizationDialog', template: '
', @@ -127,21 +127,27 @@ vi.mock('@/components/common/CustomizationDialog.vue', () => ({ } })) -vi.mock('@/components/node/NodePreview.vue', () => ({ +vi.mock(import('@/components/node/NodePreview.vue'), () => ({ default: { name: 'NodePreview', template: '
' } })) -vi.mock('@/components/sidebar/tabs/nodeLibrary/NodeTreeFolder.vue', () => ({ - default: { name: 'NodeTreeFolder', template: '
', props: ['node'] } -})) - -vi.mock('@/components/sidebar/tabs/nodeLibrary/NodeTreeLeaf.vue', () => ({ - default: { - name: 'NodeTreeLeaf', - template: '
', - props: ['node', 'openNodeHelp'] - } -})) +vi.mock( + import('@/components/sidebar/tabs/nodeLibrary/NodeTreeFolder.vue'), + () => ({ + default: { name: 'NodeTreeFolder', template: '
', props: ['node'] } + }) +) + +vi.mock( + import('@/components/sidebar/tabs/nodeLibrary/NodeTreeLeaf.vue'), + () => ({ + default: { + name: 'NodeTreeLeaf', + template: '
', + props: ['node', 'openNodeHelp'] + } + }) +) const i18n = createI18n({ legacy: false, locale: 'en', messages: { en: {} } }) diff --git a/src/components/templates/thumbnails/AudioThumbnail.test.ts b/src/components/templates/thumbnails/AudioThumbnail.test.ts index f0897bc9f08..a2076921b83 100644 --- a/src/components/templates/thumbnails/AudioThumbnail.test.ts +++ b/src/components/templates/thumbnails/AudioThumbnail.test.ts @@ -3,12 +3,15 @@ import { describe, expect, it, vi } from 'vitest' import AudioThumbnail from '@/components/templates/thumbnails/AudioThumbnail.vue' -vi.mock('@/components/templates/thumbnails/BaseThumbnail.vue', () => ({ - default: { - name: 'BaseThumbnail', - template: '
' - } -})) +vi.mock( + import('@/components/templates/thumbnails/BaseThumbnail.vue'), + () => ({ + default: { + name: 'BaseThumbnail', + template: '
' + } + }) +) describe('AudioThumbnail', () => { function renderThumbnail(props = {}) { diff --git a/src/components/templates/thumbnails/CompareSliderThumbnail.test.ts b/src/components/templates/thumbnails/CompareSliderThumbnail.test.ts index 54fdfaf3790..ce2a17d82ad 100644 --- a/src/components/templates/thumbnails/CompareSliderThumbnail.test.ts +++ b/src/components/templates/thumbnails/CompareSliderThumbnail.test.ts @@ -4,15 +4,18 @@ import { describe, expect, it, vi } from 'vitest' import CompareSliderThumbnail from '@/components/templates/thumbnails/CompareSliderThumbnail.vue' -vi.mock('@/components/templates/thumbnails/BaseThumbnail.vue', () => ({ - default: { - name: 'BaseThumbnail', - template: '
', - props: ['isHovered'] - } -})) +vi.mock( + import('@/components/templates/thumbnails/BaseThumbnail.vue'), + () => ({ + default: { + name: 'BaseThumbnail', + template: '
', + props: ['isHovered'] + } + }) +) -vi.mock('@/components/common/LazyImage.vue', () => ({ +vi.mock(import('@/components/common/LazyImage.vue'), () => ({ default: { name: 'LazyImage', template: diff --git a/src/components/templates/thumbnails/DefaultThumbnail.test.ts b/src/components/templates/thumbnails/DefaultThumbnail.test.ts index 0d795684922..fa7bf72d3c2 100644 --- a/src/components/templates/thumbnails/DefaultThumbnail.test.ts +++ b/src/components/templates/thumbnails/DefaultThumbnail.test.ts @@ -3,15 +3,18 @@ import { describe, expect, it, vi } from 'vitest' import DefaultThumbnail from '@/components/templates/thumbnails/DefaultThumbnail.vue' -vi.mock('@/components/templates/thumbnails/BaseThumbnail.vue', () => ({ - default: { - name: 'BaseThumbnail', - template: '
', - props: ['hoverZoom', 'isHovered'] - } -})) +vi.mock( + import('@/components/templates/thumbnails/BaseThumbnail.vue'), + () => ({ + default: { + name: 'BaseThumbnail', + template: '
', + props: ['hoverZoom', 'isHovered'] + } + }) +) -vi.mock('@/components/common/LazyImage.vue', () => ({ +vi.mock(import('@/components/common/LazyImage.vue'), () => ({ default: { name: 'LazyImage', template: diff --git a/src/components/templates/thumbnails/HoverDissolveThumbnail.test.ts b/src/components/templates/thumbnails/HoverDissolveThumbnail.test.ts index 8031053f880..7a2bc268975 100644 --- a/src/components/templates/thumbnails/HoverDissolveThumbnail.test.ts +++ b/src/components/templates/thumbnails/HoverDissolveThumbnail.test.ts @@ -3,15 +3,18 @@ import { describe, expect, it, vi } from 'vitest' import HoverDissolveThumbnail from '@/components/templates/thumbnails/HoverDissolveThumbnail.vue' -vi.mock('@/components/templates/thumbnails/BaseThumbnail.vue', () => ({ - default: { - name: 'BaseThumbnail', - template: '
', - props: ['isHovered'] - } -})) +vi.mock( + import('@/components/templates/thumbnails/BaseThumbnail.vue'), + () => ({ + default: { + name: 'BaseThumbnail', + template: '
', + props: ['isHovered'] + } + }) +) -vi.mock('@/components/common/LazyImage.vue', () => ({ +vi.mock(import('@/components/common/LazyImage.vue'), () => ({ default: { name: 'LazyImage', template: diff --git a/src/components/topbar/CurrentUserButton.test.ts b/src/components/topbar/CurrentUserButton.test.ts index 25b2c76de42..230d74f6ceb 100644 --- a/src/components/topbar/CurrentUserButton.test.ts +++ b/src/components/topbar/CurrentUserButton.test.ts @@ -1,6 +1,7 @@ import { render, screen } from '@testing-library/vue' import userEvent from '@testing-library/user-event' import { beforeEach, describe, expect, it, vi } from 'vitest' +import { createPinia } from 'pinia' import { defineComponent, h, ref } from 'vue' import { createI18n } from 'vue-i18n' @@ -17,12 +18,12 @@ const mockTeamWorkspaceStore = vi.hoisted(() => ({ const mockIsCloud = vi.hoisted(() => ({ value: false })) // Mock all firebase modules -vi.mock('firebase/app', () => ({ +vi.mock(import('firebase/app'), () => ({ initializeApp: vi.fn(), getApp: vi.fn() })) -vi.mock('firebase/auth', () => ({ +vi.mock(import('firebase/auth'), () => ({ getAuth: vi.fn(), setPersistence: vi.fn(), browserLocalPersistence: {}, @@ -31,24 +32,35 @@ vi.mock('firebase/auth', () => ({ signOut: vi.fn() })) -// Mock pinia -vi.mock('pinia', () => ({ - storeToRefs: vi.fn((store: Record) => store) -})) - -// Mock the useTeamWorkspaceStore -vi.mock('@/platform/workspace/stores/teamWorkspaceStore', () => ({ - useTeamWorkspaceStore: vi.fn(() => mockTeamWorkspaceStore) -})) +vi.mock( + import('@/platform/workspace/stores/teamWorkspaceStore'), + async () => { + const { defineStore } = await import('pinia') + const { computed } = await import('vue') + + return { + useTeamWorkspaceStore: defineStore('teamWorkspace', () => ({ + workspaceName: computed( + () => mockTeamWorkspaceStore.workspaceName.value + ), + initState: computed(() => mockTeamWorkspaceStore.initState.value), + isInPersonalWorkspace: computed( + () => mockTeamWorkspaceStore.isInPersonalWorkspace.value + ), + activeWorkspace: computed(() => null) + })) + } + } +) -vi.mock('@/platform/distribution/types', () => ({ +vi.mock(import('@/platform/distribution/types'), () => ({ get isCloud() { return mockIsCloud.value } })) // Mock the useCurrentUser composable -vi.mock('@/composables/auth/useCurrentUser', () => ({ +vi.mock(import('@/composables/auth/useCurrentUser'), () => ({ useCurrentUser: vi.fn(() => ({ isLoggedIn: true, userPhotoUrl: 'https://example.com/avatar.jpg', @@ -58,7 +70,7 @@ vi.mock('@/composables/auth/useCurrentUser', () => ({ })) // Mock the UserAvatar component -vi.mock('@/components/common/UserAvatar.vue', () => ({ +vi.mock(import('@/components/common/UserAvatar.vue'), () => ({ default: { name: 'UserAvatarMock', render() { @@ -68,14 +80,17 @@ vi.mock('@/components/common/UserAvatar.vue', () => ({ })) // Mock the WorkspaceProfilePic component -vi.mock('@/platform/workspace/components/WorkspaceProfilePic.vue', () => ({ - default: { - name: 'WorkspaceProfilePicMock', - render() { - return h('div', 'WorkspaceProfilePic') +vi.mock( + import('@/platform/workspace/components/WorkspaceProfilePic.vue'), + () => ({ + default: { + name: 'WorkspaceProfilePicMock', + render() { + return h('div', 'WorkspaceProfilePic') + } } - } -})) + }) +) const CurrentUserPopoverWorkspaceStub = defineComponent({ name: 'CurrentUserPopoverWorkspace', @@ -92,7 +107,7 @@ const CurrentUserPopoverWorkspaceStub = defineComponent({ }) // Mock the CurrentUserPopoverLegacy component -vi.mock('./CurrentUserPopoverLegacy.vue', () => ({ +vi.mock(import('./CurrentUserPopoverLegacy.vue'), () => ({ default: defineComponent({ name: 'CurrentUserPopoverLegacyMock', emits: ['close'], @@ -131,7 +146,7 @@ describe('CurrentUserButton', () => { const result = render(CurrentUserButton, { global: { - plugins: [i18n], + plugins: [i18n, createPinia()], stubs: { CurrentUserPopoverWorkspace: CurrentUserPopoverWorkspaceStub, Popover: defineComponent({ diff --git a/src/components/topbar/CurrentUserPopoverLegacy.test.ts b/src/components/topbar/CurrentUserPopoverLegacy.test.ts index 957e3b88063..5426f1c4a0a 100644 --- a/src/components/topbar/CurrentUserPopoverLegacy.test.ts +++ b/src/components/topbar/CurrentUserPopoverLegacy.test.ts @@ -14,7 +14,7 @@ import CurrentUserPopoverLegacy from './CurrentUserPopoverLegacy.vue' const mockShowSettingsDialog = vi.fn() const mockShowTopUpCreditsDialog = vi.fn() -vi.mock('@/platform/settings/composables/useSettingsDialog', () => ({ +vi.mock(import('@/platform/settings/composables/useSettingsDialog'), () => ({ useSettingsDialog: vi.fn(() => ({ show: mockShowSettingsDialog, hide: vi.fn(), @@ -32,7 +32,7 @@ afterAll(() => { }) const mockHandleSignOut = vi.fn() -vi.mock('@/composables/auth/useCurrentUser', () => ({ +vi.mock(import('@/composables/auth/useCurrentUser'), () => ({ useCurrentUser: vi.fn(() => ({ userPhotoUrl: 'https://example.com/avatar.jpg', userDisplayName: 'Test User', @@ -41,7 +41,7 @@ vi.mock('@/composables/auth/useCurrentUser', () => ({ })) })) -vi.mock('@/services/dialogService', () => ({ +vi.mock(import('@/services/dialogService'), () => ({ useDialogService: vi.fn(() => ({ showTopUpCreditsDialog: mockShowTopUpCreditsDialog })) @@ -74,7 +74,7 @@ const mockIsTeamPlan = ref(false) const mockCanTopUp = ref(true) const mockCanSubscribeSelfServe = ref(false) -vi.mock('@/composables/billing/useBillingContext', () => ({ +vi.mock(import('@/composables/billing/useBillingContext'), () => ({ useBillingContext: vi.fn(() => ({ canAccessSubscriptionFeatures: mockCanAccessSubscriptionFeatures, tier: mockTier, @@ -86,14 +86,17 @@ vi.mock('@/composables/billing/useBillingContext', () => ({ })) })) -vi.mock('@/platform/workspace/composables/useBillingCapabilities', () => ({ - useBillingCapabilities: () => ({ - canTopUp: mockCanTopUp, - canSubscribeSelfServe: mockCanSubscribeSelfServe +vi.mock( + import('@/platform/workspace/composables/useBillingCapabilities'), + () => ({ + useBillingCapabilities: () => ({ + canTopUp: mockCanTopUp, + canSubscribeSelfServe: mockCanSubscribeSelfServe + }) }) -})) +) -vi.mock('@/components/common/UserAvatar.vue', () => ({ +vi.mock(import('@/components/common/UserAvatar.vue'), () => ({ default: { name: 'UserAvatarMock', render() { @@ -102,11 +105,11 @@ vi.mock('@/components/common/UserAvatar.vue', () => ({ } })) -vi.mock('@/base/credits/comfyCredits', () => ({ +vi.mock(import('@/base/credits/comfyCredits'), () => ({ formatCreditsFromCents: vi.fn(({ cents }) => (cents / 100).toString()) })) -vi.mock('@/composables/useExternalLink', () => ({ +vi.mock(import('@/composables/useExternalLink'), () => ({ useExternalLink: vi.fn(() => ({ buildDocsUrl: vi.fn((path) => `https://docs.comfy.org${path}`), docsPaths: { @@ -115,7 +118,7 @@ vi.mock('@/composables/useExternalLink', () => ({ })) })) -vi.mock('@/platform/telemetry', () => ({ +vi.mock(import('@/platform/telemetry'), () => ({ useTelemetry: vi.fn(() => ({ trackAddApiCreditButtonClicked: vi.fn() })) diff --git a/src/components/topbar/TopbarSubscribeButton.test.ts b/src/components/topbar/TopbarSubscribeButton.test.ts index 36d172a7421..ae13a439caf 100644 --- a/src/components/topbar/TopbarSubscribeButton.test.ts +++ b/src/components/topbar/TopbarSubscribeButton.test.ts @@ -1,4 +1,5 @@ import { describe, expect, it, vi } from 'vitest' +import { createPinia } from 'pinia' import { createI18n } from 'vue-i18n' import { render, screen } from '@testing-library/vue' @@ -9,7 +10,7 @@ import TopbarSubscribeButton from './TopbarSubscribeButton.vue' const mockIsCloud = vi.hoisted(() => ({ value: true })) -vi.mock('@/platform/distribution/types', () => ({ +vi.mock(import('@/platform/distribution/types'), () => ({ get isCloud() { return mockIsCloud.value } @@ -17,8 +18,8 @@ vi.mock('@/platform/distribution/types', () => ({ const mockShowPricingTable = vi.fn() -vi.mock( - '@/platform/cloud/subscription/composables/useSubscriptionDialog', +vi.mock( + import('@/platform/cloud/subscription/composables/useSubscriptionDialog'), () => ({ useSubscriptionDialog: vi.fn(() => ({ showPricingTable: mockShowPricingTable @@ -26,20 +27,18 @@ vi.mock( }) ) -vi.mock('@/composables/billing/useBillingContext', () => ({ +vi.mock(import('@/composables/billing/useBillingContext'), () => ({ useBillingContext: vi.fn(() => ({ isFreeTier: { value: true } })) })) -vi.mock('pinia') - -vi.mock('firebase/app', () => ({ +vi.mock(import('firebase/app'), () => ({ initializeApp: vi.fn(), getApp: vi.fn() })) -vi.mock('firebase/auth', () => ({ +vi.mock(import('firebase/auth'), () => ({ getAuth: vi.fn(), setPersistence: vi.fn(), browserLocalPersistence: {}, @@ -56,7 +55,7 @@ function renderComponent() { return render(TopbarSubscribeButton, { global: { - plugins: [i18n] + plugins: [i18n, createPinia()] } }) } diff --git a/src/components/topbar/WorkflowTab.test.ts b/src/components/topbar/WorkflowTab.test.ts index dc1b9a6ac53..3464184659b 100644 --- a/src/components/topbar/WorkflowTab.test.ts +++ b/src/components/topbar/WorkflowTab.test.ts @@ -21,7 +21,7 @@ const { mockWorkflowStatus, mockCloseWorkflow } = await vi.hoisted(async () => { } }) -vi.mock('@/stores/authStore', () => ({ +vi.mock(import('@/stores/authStore'), () => ({ useAuthStore: () => ({ currentUser: null, isAuthenticated: false, @@ -29,7 +29,7 @@ vi.mock('@/stores/authStore', () => ({ }) })) -vi.mock('@/stores/executionStore', async (importOriginal) => { +vi.mock(import('@/stores/executionStore'), async (importOriginal) => { const actual = await importOriginal() return { WORKFLOW_STATUS_I18N_KEYS: actual.WORKFLOW_STATUS_I18N_KEYS, @@ -42,30 +42,37 @@ vi.mock('@/stores/executionStore', async (importOriginal) => { } }) -vi.mock('@/composables/usePragmaticDragAndDrop', () => ({ +vi.mock(import('@/composables/usePragmaticDragAndDrop'), () => ({ usePragmaticDraggable: vi.fn(), usePragmaticDroppable: vi.fn() })) -vi.mock('@/composables/useWorkflowActionsMenu', () => ({ +vi.mock(import('@/composables/useWorkflowActionsMenu'), () => ({ useWorkflowActionsMenu: () => ({ menuItems: { value: [] } }) })) -vi.mock('@/platform/workflow/core/services/workflowService', () => ({ - useWorkflowService: () => ({ - closeWorkflow: mockCloseWorkflow +vi.mock( + import('@/platform/workflow/core/services/workflowService'), + () => ({ + useWorkflowService: () => ({ + closeWorkflow: mockCloseWorkflow + }) }) -})) +) + +vi.mock( + import('@/renderer/core/thumbnail/useWorkflowThumbnail'), -vi.mock('@/renderer/core/thumbnail/useWorkflowThumbnail', () => ({ - useWorkflowThumbnail: () => ({ - getThumbnail: vi.fn(() => null) + () => ({ + useWorkflowThumbnail: () => ({ + getThumbnail: vi.fn(() => null) + }) }) -})) +) -vi.mock('./WorkflowTabPopover.vue', () => ({ +vi.mock(import('./WorkflowTabPopover.vue'), () => ({ default: { render: () => null, methods: { diff --git a/src/components/topbar/WorkflowTabs.test.ts b/src/components/topbar/WorkflowTabs.test.ts index 38dcd73587b..80f5cb84039 100644 --- a/src/components/topbar/WorkflowTabs.test.ts +++ b/src/components/topbar/WorkflowTabs.test.ts @@ -13,8 +13,8 @@ import { useAgentPanelStore } from '@/workbench/extensions/agent/stores/agent/ag import WorkflowTabs from './WorkflowTabs.vue' -vi.mock('firebase/auth') -vi.mock('vuefire', () => ({ useFirebaseAuth: vi.fn() })) +vi.mock(import('firebase/auth')) +vi.mock(import('vuefire'), () => ({ useFirebaseAuth: vi.fn() })) const distribution = vi.hoisted(() => ({ isCloud: false, @@ -29,7 +29,7 @@ const overflowObservers = vi.hoisted< }> >(() => []) -vi.mock('@/platform/distribution/types', () => ({ +vi.mock(import('@/platform/distribution/types'), () => ({ get isCloud() { return distribution.isCloud }, @@ -41,7 +41,7 @@ vi.mock('@/platform/distribution/types', () => ({ } })) -vi.mock('@/composables/auth/useCurrentUser', () => ({ +vi.mock(import('@/composables/auth/useCurrentUser'), () => ({ useCurrentUser: () => ({ isLoggedIn: { value: false }, userEmail: { value: undefined } @@ -50,47 +50,53 @@ vi.mock('@/composables/auth/useCurrentUser', () => ({ const openFeedbackDialog = vi.hoisted(() => vi.fn()) const openWorkflow = vi.hoisted(() => vi.fn()) -vi.mock('@/platform/support/feedbackDialog', () => ({ +vi.mock(import('@/platform/support/feedbackDialog'), () => ({ openFeedbackDialog })) -vi.mock('@/composables/useWorkflowStatusDismissal', () => ({ +vi.mock(import('@/composables/useWorkflowStatusDismissal'), () => ({ useWorkflowStatusDismissal: vi.fn() })) -vi.mock('@/composables/element/useOverflowObserver', async () => { - const { ref } = await import('vue') - return { - useOverflowObserver: () => { - const observer = { - isOverflowing: ref(false), - checkOverflow: vi.fn() +vi.mock( + import('@/composables/element/useOverflowObserver'), + async () => { + const { ref } = await import('vue') + return { + useOverflowObserver: () => { + const observer = { + isOverflowing: ref(false), + checkOverflow: vi.fn() + } + overflowObservers.push(observer) + return observer } - overflowObservers.push(observer) - return observer } } -}) - -vi.mock('@/platform/workflow/core/services/workflowService', () => ({ - useWorkflowService: () => ({ - openWorkflow, - closeWorkflow: vi.fn() +) + +vi.mock( + import('@/platform/workflow/core/services/workflowService'), + () => ({ + useWorkflowService: () => ({ + openWorkflow, + closeWorkflow: vi.fn() + }) }) -})) +) -vi.mock('@/utils/mouseDownUtil', () => ({ +vi.mock(import('@/utils/mouseDownUtil'), () => ({ whileMouseDown: vi.fn() })) -vi.mock('./WorkflowOverflowMenu.vue', () => ({ +vi.mock(import('./WorkflowOverflowMenu.vue'), () => ({ default: defineComponent({ name: 'WorkflowOverflowMenuStub', render: () => h('div', { 'data-testid': 'workflow-overflow-menu' }) }) })) -vi.mock('./WorkflowTab.vue', () => ({ +vi.mock(import('./WorkflowTab.vue'), () => ({ default: defineComponent({ name: 'WorkflowTabStub', props: { @@ -105,14 +111,14 @@ vi.mock('./WorkflowTab.vue', () => ({ }) })) -vi.mock('./CurrentUserButton.vue', () => ({ +vi.mock(import('./CurrentUserButton.vue'), () => ({ default: defineComponent({ name: 'CurrentUserButtonStub', render: () => h('div') }) })) -vi.mock('./LoginButton.vue', () => ({ +vi.mock(import('./LoginButton.vue'), () => ({ default: defineComponent({ name: 'LoginButtonStub', render: () => h('div') diff --git a/src/components/ui/search-input/SearchInput.test.ts b/src/components/ui/search-input/SearchInput.test.ts index 7c49314ce3d..9f1dbcd65cc 100644 --- a/src/components/ui/search-input/SearchInput.test.ts +++ b/src/components/ui/search-input/SearchInput.test.ts @@ -6,7 +6,7 @@ import { createI18n } from 'vue-i18n' import SearchInput from './SearchInput.vue' -vi.mock('@vueuse/core', () => ({ +vi.mock(import('@vueuse/core'), () => ({ watchDebounced: vi.fn((source, cb, opts) => { let timer: ReturnType | null = null return watch(source, (val: string) => { diff --git a/src/components/videoEdit/VideoFilmstripTrim.test.ts b/src/components/videoEdit/VideoFilmstripTrim.test.ts index e5f5a108ddd..563765711d6 100644 --- a/src/components/videoEdit/VideoFilmstripTrim.test.ts +++ b/src/components/videoEdit/VideoFilmstripTrim.test.ts @@ -11,7 +11,7 @@ const { activeHandle } = vi.hoisted(() => { } }) -vi.mock('@/composables/useRangeEditor', () => ({ +vi.mock(import('@/composables/useRangeEditor'), () => ({ useRangeEditor: () => ({ startDrag: vi.fn(), activeHandle diff --git a/src/components/videoEdit/WidgetVideoEdit.test.ts b/src/components/videoEdit/WidgetVideoEdit.test.ts index 93fe83d0210..39664d570f5 100644 --- a/src/components/videoEdit/WidgetVideoEdit.test.ts +++ b/src/components/videoEdit/WidgetVideoEdit.test.ts @@ -34,18 +34,18 @@ const mocks = vi.hoisted(() => { return mocks }) -vi.mock('@/scripts/app', () => ({ +vi.mock(import('@/scripts/app'), () => ({ app: { rootGraph: {}, canvas: { graph: { getNodeById: () => hostNode } } } })) -vi.mock('@/utils/graphTraversalUtil', () => ({ +vi.mock(import('@/utils/graphTraversalUtil'), () => ({ getNodeByLocatorId: mocks.getNodeByLocatorId })) -vi.mock('@/composables/video/useVideoSourceUrl', () => { +vi.mock(import('@/composables/video/useVideoSourceUrl'), () => { // eslint-disable-next-line @typescript-eslint/no-require-imports const { ref: createRef } = require('vue') return { @@ -56,7 +56,7 @@ vi.mock('@/composables/video/useVideoSourceUrl', () => { } }) -vi.mock('@/composables/video/useVideoFilmstrip', () => { +vi.mock(import('@/composables/video/useVideoFilmstrip'), () => { // eslint-disable-next-line @typescript-eslint/no-require-imports const { ref: createRef } = require('vue') return {