mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-04 23:20:07 +00:00
refactor: remove any types from test files (batch 1)
Remove explicit any types from 7 test files: - useWatchWidget.test.ts (3 instances) - LGraphNodeProperties.test.ts (2 instances) - versionCompatibilityStore.test.ts (2 instances) - workflowStore.test.ts (2 instances) - useRemoteWidget.test.ts (2 instances) - registrySearchGateway.test.ts (2 instances) - colorUtil.test.ts (2 instances) Changes: - Used `unknown` for truly unknown values instead of `any` - Used `Partial<T>` with type assertions for mock objects - Used `ReturnType<typeof func>` to derive proper types - Used proper typing for promise resolvers and spy mocks - Used `this: unknown` with proper casting for function contexts All changes pass typecheck and tests.
This commit is contained in:
@@ -7,7 +7,7 @@ import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
|
||||
// Mock useChainCallback
|
||||
vi.mock('@/composables/functional/useChainCallback', () => ({
|
||||
useChainCallback: vi.fn((original, newCallback) => {
|
||||
return function (this: any, ...args: any[]) {
|
||||
return function (this: unknown, ...args: unknown[]) {
|
||||
original?.call(this, ...args)
|
||||
newCallback.call(this, ...args)
|
||||
}
|
||||
@@ -18,8 +18,8 @@ describe('useComputedWithWidgetWatch', () => {
|
||||
const createMockNode = (
|
||||
widgets: Array<{
|
||||
name: string
|
||||
value: any
|
||||
callback?: (...args: any[]) => void
|
||||
value: unknown
|
||||
callback?: (...args: unknown[]) => void
|
||||
}> = []
|
||||
) => {
|
||||
const mockNode = {
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { LGraphNodeProperties } from '@/lib/litegraph/src/LGraphNodeProperties'
|
||||
import type { LGraph, LGraphNode } from '@/lib/litegraph/src/litegraph'
|
||||
|
||||
describe('LGraphNodeProperties', () => {
|
||||
let mockNode: any
|
||||
let mockGraph: any
|
||||
let mockNode: LGraphNode
|
||||
let mockGraph: LGraph
|
||||
|
||||
beforeEach(() => {
|
||||
mockGraph = {
|
||||
trigger: vi.fn()
|
||||
}
|
||||
} as unknown as LGraph
|
||||
|
||||
mockNode = {
|
||||
id: 123,
|
||||
title: 'Test Node',
|
||||
flags: {},
|
||||
graph: mockGraph
|
||||
}
|
||||
} as unknown as LGraphNode
|
||||
})
|
||||
|
||||
describe('property tracking', () => {
|
||||
|
||||
@@ -30,8 +30,8 @@ vi.mock('@vueuse/core', () => ({
|
||||
|
||||
describe('useVersionCompatibilityStore', () => {
|
||||
let store: ReturnType<typeof useVersionCompatibilityStore>
|
||||
let mockSystemStatsStore: any
|
||||
let mockSettingStore: any
|
||||
let mockSystemStatsStore: unknown
|
||||
let mockSettingStore: unknown
|
||||
|
||||
beforeEach(() => {
|
||||
setActivePinia(createPinia())
|
||||
@@ -49,8 +49,12 @@ describe('useVersionCompatibilityStore', () => {
|
||||
get: vi.fn(() => false) // Default to warnings enabled
|
||||
}
|
||||
|
||||
vi.mocked(useSystemStatsStore).mockReturnValue(mockSystemStatsStore)
|
||||
vi.mocked(useSettingStore).mockReturnValue(mockSettingStore)
|
||||
vi.mocked(useSystemStatsStore).mockReturnValue(
|
||||
mockSystemStatsStore as ReturnType<typeof useSystemStatsStore>
|
||||
)
|
||||
vi.mocked(useSettingStore).mockReturnValue(
|
||||
mockSettingStore as ReturnType<typeof useSettingStore>
|
||||
)
|
||||
|
||||
store = useVersionCompatibilityStore()
|
||||
})
|
||||
@@ -61,13 +65,17 @@ describe('useVersionCompatibilityStore', () => {
|
||||
|
||||
describe('version compatibility detection', () => {
|
||||
it('should detect frontend is outdated when required version is higher', async () => {
|
||||
mockSystemStatsStore.systemStats = {
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).systemStats = {
|
||||
system: {
|
||||
comfyui_version: '1.25.0',
|
||||
required_frontend_version: '1.25.0'
|
||||
}
|
||||
}
|
||||
mockSystemStatsStore.isInitialized = true
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).isInitialized = true
|
||||
|
||||
await store.checkVersionCompatibility()
|
||||
|
||||
@@ -79,13 +87,17 @@ describe('useVersionCompatibilityStore', () => {
|
||||
it('should not warn when frontend is newer than backend', async () => {
|
||||
// Frontend: 1.24.0, Backend: 1.23.0, Required: 1.23.0
|
||||
// Frontend meets required version, no warning needed
|
||||
mockSystemStatsStore.systemStats = {
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).systemStats = {
|
||||
system: {
|
||||
comfyui_version: '1.23.0',
|
||||
required_frontend_version: '1.23.0'
|
||||
}
|
||||
}
|
||||
mockSystemStatsStore.isInitialized = true
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).isInitialized = true
|
||||
|
||||
await store.checkVersionCompatibility()
|
||||
|
||||
@@ -95,13 +107,17 @@ describe('useVersionCompatibilityStore', () => {
|
||||
})
|
||||
|
||||
it('should not detect mismatch when versions are compatible', async () => {
|
||||
mockSystemStatsStore.systemStats = {
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).systemStats = {
|
||||
system: {
|
||||
comfyui_version: '1.24.0',
|
||||
required_frontend_version: '1.24.0'
|
||||
}
|
||||
}
|
||||
mockSystemStatsStore.isInitialized = true
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).isInitialized = true
|
||||
|
||||
await store.checkVersionCompatibility()
|
||||
|
||||
@@ -111,13 +127,17 @@ describe('useVersionCompatibilityStore', () => {
|
||||
})
|
||||
|
||||
it('should handle missing version information gracefully', async () => {
|
||||
mockSystemStatsStore.systemStats = {
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).systemStats = {
|
||||
system: {
|
||||
comfyui_version: '',
|
||||
required_frontend_version: ''
|
||||
}
|
||||
}
|
||||
mockSystemStatsStore.isInitialized = true
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).isInitialized = true
|
||||
|
||||
await store.checkVersionCompatibility()
|
||||
|
||||
@@ -127,13 +147,17 @@ describe('useVersionCompatibilityStore', () => {
|
||||
})
|
||||
|
||||
it('should not detect mismatch when versions are not valid semver', async () => {
|
||||
mockSystemStatsStore.systemStats = {
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).systemStats = {
|
||||
system: {
|
||||
comfyui_version: '080e6d4af809a46852d1c4b7ed85f06e8a3a72be', // git hash
|
||||
required_frontend_version: 'not-a-version' // invalid semver format
|
||||
}
|
||||
}
|
||||
mockSystemStatsStore.isInitialized = true
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).isInitialized = true
|
||||
|
||||
await store.checkVersionCompatibility()
|
||||
|
||||
@@ -144,13 +168,17 @@ describe('useVersionCompatibilityStore', () => {
|
||||
|
||||
it('should not warn when frontend exceeds required version', async () => {
|
||||
// Frontend: 1.24.0 (from mock config)
|
||||
mockSystemStatsStore.systemStats = {
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).systemStats = {
|
||||
system: {
|
||||
comfyui_version: '1.22.0', // Backend is older
|
||||
required_frontend_version: '1.23.0' // Required is 1.23.0, frontend 1.24.0 meets this
|
||||
}
|
||||
}
|
||||
mockSystemStatsStore.isInitialized = true
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).isInitialized = true
|
||||
|
||||
await store.checkVersionCompatibility()
|
||||
|
||||
@@ -164,13 +192,17 @@ describe('useVersionCompatibilityStore', () => {
|
||||
it('should show warning when there is a version mismatch and not dismissed', async () => {
|
||||
// No dismissals in storage
|
||||
mockDismissalStorage.value = {}
|
||||
mockSystemStatsStore.systemStats = {
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).systemStats = {
|
||||
system: {
|
||||
comfyui_version: '1.25.0',
|
||||
required_frontend_version: '1.25.0'
|
||||
}
|
||||
}
|
||||
mockSystemStatsStore.isInitialized = true
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).isInitialized = true
|
||||
|
||||
await store.checkVersionCompatibility()
|
||||
|
||||
@@ -184,13 +216,17 @@ describe('useVersionCompatibilityStore', () => {
|
||||
'1.24.0-1.25.0-1.25.0': futureTime
|
||||
}
|
||||
|
||||
mockSystemStatsStore.systemStats = {
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).systemStats = {
|
||||
system: {
|
||||
comfyui_version: '1.25.0',
|
||||
required_frontend_version: '1.25.0'
|
||||
}
|
||||
}
|
||||
mockSystemStatsStore.isInitialized = true
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).isInitialized = true
|
||||
|
||||
await store.checkVersionCompatibility()
|
||||
|
||||
@@ -198,13 +234,17 @@ describe('useVersionCompatibilityStore', () => {
|
||||
})
|
||||
|
||||
it('should not show warning when no version mismatch', async () => {
|
||||
mockSystemStatsStore.systemStats = {
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).systemStats = {
|
||||
system: {
|
||||
comfyui_version: '1.24.0',
|
||||
required_frontend_version: '1.24.0'
|
||||
}
|
||||
}
|
||||
mockSystemStatsStore.isInitialized = true
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).isInitialized = true
|
||||
|
||||
await store.checkVersionCompatibility()
|
||||
|
||||
@@ -213,35 +253,45 @@ describe('useVersionCompatibilityStore', () => {
|
||||
|
||||
it('should not show warning when disabled via setting', async () => {
|
||||
// Enable the disable setting
|
||||
mockSettingStore.get.mockReturnValue(true)
|
||||
;(
|
||||
mockSettingStore as { get: ReturnType<typeof vi.fn> }
|
||||
).get.mockReturnValue(true)
|
||||
|
||||
// Set up version mismatch that would normally show warning
|
||||
mockSystemStatsStore.systemStats = {
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).systemStats = {
|
||||
system: {
|
||||
comfyui_version: '1.25.0',
|
||||
required_frontend_version: '1.25.0'
|
||||
}
|
||||
}
|
||||
mockSystemStatsStore.isInitialized = true
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).isInitialized = true
|
||||
|
||||
await store.checkVersionCompatibility()
|
||||
|
||||
expect(store.shouldShowWarning).toBe(false)
|
||||
expect(mockSettingStore.get).toHaveBeenCalledWith(
|
||||
'Comfy.VersionCompatibility.DisableWarnings'
|
||||
)
|
||||
expect(
|
||||
(mockSettingStore as { get: ReturnType<typeof vi.fn> }).get
|
||||
).toHaveBeenCalledWith('Comfy.VersionCompatibility.DisableWarnings')
|
||||
})
|
||||
})
|
||||
|
||||
describe('warning messages', () => {
|
||||
it('should generate outdated message when frontend is outdated', async () => {
|
||||
mockSystemStatsStore.systemStats = {
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).systemStats = {
|
||||
system: {
|
||||
comfyui_version: '1.25.0',
|
||||
required_frontend_version: '1.25.0'
|
||||
}
|
||||
}
|
||||
mockSystemStatsStore.isInitialized = true
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).isInitialized = true
|
||||
|
||||
await store.checkVersionCompatibility()
|
||||
|
||||
@@ -253,13 +303,17 @@ describe('useVersionCompatibilityStore', () => {
|
||||
})
|
||||
|
||||
it('should return null when no mismatch', async () => {
|
||||
mockSystemStatsStore.systemStats = {
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).systemStats = {
|
||||
system: {
|
||||
comfyui_version: '1.24.0',
|
||||
required_frontend_version: '1.24.0'
|
||||
}
|
||||
}
|
||||
mockSystemStatsStore.isInitialized = true
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).isInitialized = true
|
||||
|
||||
await store.checkVersionCompatibility()
|
||||
|
||||
@@ -272,13 +326,17 @@ describe('useVersionCompatibilityStore', () => {
|
||||
const mockNow = 1000000
|
||||
vi.spyOn(Date, 'now').mockReturnValue(mockNow)
|
||||
|
||||
mockSystemStatsStore.systemStats = {
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).systemStats = {
|
||||
system: {
|
||||
comfyui_version: '1.25.0',
|
||||
required_frontend_version: '1.25.0'
|
||||
}
|
||||
}
|
||||
mockSystemStatsStore.isInitialized = true
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).isInitialized = true
|
||||
|
||||
await store.checkVersionCompatibility()
|
||||
store.dismissWarning()
|
||||
@@ -295,13 +353,17 @@ describe('useVersionCompatibilityStore', () => {
|
||||
'1.24.0-1.25.0-1.25.0': futureTime
|
||||
}
|
||||
|
||||
mockSystemStatsStore.systemStats = {
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).systemStats = {
|
||||
system: {
|
||||
comfyui_version: '1.25.0',
|
||||
required_frontend_version: '1.25.0'
|
||||
}
|
||||
}
|
||||
mockSystemStatsStore.isInitialized = true
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).isInitialized = true
|
||||
|
||||
await store.initialize()
|
||||
|
||||
@@ -314,13 +376,17 @@ describe('useVersionCompatibilityStore', () => {
|
||||
'1.24.0-1.25.0-1.25.0': pastTime
|
||||
}
|
||||
|
||||
mockSystemStatsStore.systemStats = {
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).systemStats = {
|
||||
system: {
|
||||
comfyui_version: '1.25.0',
|
||||
required_frontend_version: '1.25.0'
|
||||
}
|
||||
}
|
||||
mockSystemStatsStore.isInitialized = true
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).isInitialized = true
|
||||
|
||||
await store.initialize()
|
||||
|
||||
@@ -334,13 +400,17 @@ describe('useVersionCompatibilityStore', () => {
|
||||
'1.24.0-1.25.0-1.25.0': futureTime // Different version was dismissed
|
||||
}
|
||||
|
||||
mockSystemStatsStore.systemStats = {
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).systemStats = {
|
||||
system: {
|
||||
comfyui_version: '1.26.0',
|
||||
required_frontend_version: '1.26.0'
|
||||
}
|
||||
}
|
||||
mockSystemStatsStore.isInitialized = true
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).isInitialized = true
|
||||
|
||||
await store.initialize()
|
||||
|
||||
@@ -351,8 +421,12 @@ describe('useVersionCompatibilityStore', () => {
|
||||
describe('initialization', () => {
|
||||
it('should fetch system stats if not available', async () => {
|
||||
const { until } = await import('@vueuse/core')
|
||||
mockSystemStatsStore.systemStats = null
|
||||
mockSystemStatsStore.isInitialized = false
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).systemStats = null
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).isInitialized = false
|
||||
|
||||
await store.initialize()
|
||||
|
||||
@@ -361,13 +435,17 @@ describe('useVersionCompatibilityStore', () => {
|
||||
|
||||
it('should not fetch system stats if already available', async () => {
|
||||
const { until } = await import('@vueuse/core')
|
||||
mockSystemStatsStore.systemStats = {
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).systemStats = {
|
||||
system: {
|
||||
comfyui_version: '1.24.0',
|
||||
required_frontend_version: '1.24.0'
|
||||
}
|
||||
}
|
||||
mockSystemStatsStore.isInitialized = true
|
||||
;(
|
||||
mockSystemStatsStore as { systemStats: unknown; isInitialized: boolean }
|
||||
).isInitialized = true
|
||||
|
||||
await store.initialize()
|
||||
|
||||
|
||||
@@ -364,10 +364,11 @@ describe('useWorkflowStore', () => {
|
||||
|
||||
// Mock super.rename
|
||||
vi.spyOn(Object.getPrototypeOf(workflow), 'rename').mockImplementation(
|
||||
async function (this: any, newPath: string) {
|
||||
this.path = newPath
|
||||
return this
|
||||
} as any
|
||||
async function (this: unknown, ...args: unknown[]) {
|
||||
const newPath = args[0] as string
|
||||
;(this as typeof workflow).path = newPath
|
||||
return this as typeof workflow
|
||||
}
|
||||
)
|
||||
|
||||
// Perform rename
|
||||
@@ -387,10 +388,11 @@ describe('useWorkflowStore', () => {
|
||||
|
||||
// Mock super.rename
|
||||
vi.spyOn(Object.getPrototypeOf(workflow), 'rename').mockImplementation(
|
||||
async function (this: any, newPath: string) {
|
||||
this.path = newPath
|
||||
return this
|
||||
} as any
|
||||
async function (this: unknown, ...args: unknown[]) {
|
||||
const newPath = args[0] as string
|
||||
;(this as typeof workflow).path = newPath
|
||||
return this as typeof workflow
|
||||
}
|
||||
)
|
||||
|
||||
// Perform rename
|
||||
|
||||
@@ -498,7 +498,7 @@ describe('useRemoteWidget', () => {
|
||||
})
|
||||
|
||||
it('should handle rapid cache clearing during fetch', async () => {
|
||||
let resolvePromise: (value: any) => void
|
||||
let resolvePromise: (value: { data: unknown }) => void
|
||||
const delayedPromise = new Promise((resolve) => {
|
||||
resolvePromise = resolve
|
||||
})
|
||||
@@ -519,7 +519,7 @@ describe('useRemoteWidget', () => {
|
||||
})
|
||||
|
||||
it('should handle widget destroyed during fetch', async () => {
|
||||
let resolvePromise: (value: any) => void
|
||||
let resolvePromise: (value: { data: unknown }) => void
|
||||
const delayedPromise = new Promise((resolve) => {
|
||||
resolvePromise = resolve
|
||||
})
|
||||
|
||||
@@ -9,8 +9,8 @@ vi.mock('@/services/providers/algoliaSearchProvider')
|
||||
vi.mock('@/services/providers/registrySearchProvider')
|
||||
|
||||
describe('useRegistrySearchGateway', () => {
|
||||
let consoleWarnSpy: any
|
||||
let consoleInfoSpy: any
|
||||
let consoleWarnSpy: ReturnType<typeof vi.spyOn>
|
||||
let consoleInfoSpy: ReturnType<typeof vi.spyOn>
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import type { ColorAdjustOptions } from '@/utils/colorUtil'
|
||||
import {
|
||||
adjustColor,
|
||||
hexToRgb,
|
||||
@@ -22,13 +23,16 @@ interface ColorTestCase {
|
||||
type ColorFormat = 'hex' | 'rgb' | 'rgba' | 'hsl' | 'hsla'
|
||||
|
||||
vi.mock('es-toolkit/compat', () => ({
|
||||
memoize: (fn: any) => fn
|
||||
memoize: <T extends (...args: unknown[]) => unknown>(fn: T) => fn
|
||||
}))
|
||||
|
||||
const targetOpacity = 0.5
|
||||
const targetLightness = 0.5
|
||||
|
||||
const assertColorVariationsMatch = (variations: string[], adjustment: any) => {
|
||||
const assertColorVariationsMatch = (
|
||||
variations: string[],
|
||||
adjustment: ColorAdjustOptions
|
||||
) => {
|
||||
for (let i = 0; i < variations.length - 1; i++) {
|
||||
expect(adjustColor(variations[i], adjustment)).toBe(
|
||||
adjustColor(variations[i + 1], adjustment)
|
||||
|
||||
Reference in New Issue
Block a user