mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-07 16:40:05 +00:00
Road to No explicit any: Group 8 (part 6) test files (#8344)
## Summary
This PR removes unsafe type assertions ("as unknown as Type") from test
files and improves type safety across the codebase.
### Key Changes
#### Type Safety Improvements
- Removed all instances of "as unknown as" patterns from test files
- Used proper factory functions from litegraphTestUtils instead of
custom mocks
- Made incomplete mocks explicit using Partial<T> types
- Fixed DialogStore mocking with proper interface exports
- Improved type safety with satisfies operator where applicable
#### App Parameter Removal
- **Removed the unused `app` parameter from all ComfyExtension interface
methods**
- The app parameter was always undefined at runtime as it was never
passed from invokeExtensions
- Affected methods: init, setup, addCustomNodeDefs,
beforeRegisterNodeDef, beforeRegisterVueAppNodeDefs,
registerCustomNodes, loadedGraphNode, nodeCreated, beforeConfigureGraph,
afterConfigureGraph
##### Breaking Change Analysis
Verified via Sourcegraph that this is NOT a breaking change:
- Searched all 10 affected methods across GitHub repositories
- Only one external repository
([drawthingsai/draw-things-comfyui](https://github.com/drawthingsai/draw-things-comfyui))
declares the app parameter in their extension methods
- That repository never actually uses the app parameter (just declares
it in the function signature)
- All other repositories already omit the app parameter
- Search queries used:
- [init method
search](https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/.*+lang:typescript+%22init%28app%22+-repo:Comfy-Org/ComfyUI_frontend&patternType=standard)
- [setup method
search](https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/.*+lang:typescript+%22setup%28app%22+-repo:Comfy-Org/ComfyUI_frontend&patternType=standard)
- Similar searches for all 10 methods confirmed no usage
### Files Changed
Test files:
-
src/components/settings/widgets/__tests__/WidgetInputNumberInput.test.ts
- src/services/keybindingService.escape.test.ts
- src/services/keybindingService.forwarding.test.ts
- src/utils/__tests__/newUserService.test.ts →
src/utils/__tests__/useNewUserService.test.ts
- src/services/jobOutputCache.test.ts
-
src/renderer/extensions/vueNodes/widgets/composables/useRemoteWidget.test.ts
-
src/renderer/extensions/vueNodes/widgets/composables/useIntWidget.test.ts
-
src/renderer/extensions/vueNodes/widgets/composables/useFloatWidget.test.ts
Source files:
- src/types/comfy.ts - Removed app parameter from ComfyExtension
interface
- src/services/extensionService.ts - Improved type safety with
FunctionPropertyNames helper
- src/scripts/metadata/isobmff.ts - Fixed extractJson return type per
review
- src/extensions/core/*.ts - Updated extension implementations
- src/scripts/app.ts - Updated app initialization
### Testing
- All existing tests pass
- Type checking passes
- ESLint/oxlint checks pass
- No breaking changes for external repositories
Part of the "Road to No Explicit Any" initiative.
### Previous PRs in this series:
- Part 2: #7401
- Part 3: #7935
- Part 4: #7970
- Part 5: #8064
- Part 6: #8083
- Part 7: #8092
- Part 8 Group 1: #8253
- Part 8 Group 2: #8258
- Part 8 Group 3: #8304
- Part 8 Group 4: #8314
- Part 8 Group 5: #8329
- Part 8 Group 6: #8344 (this PR)
This commit is contained in:
committed by
GitHub
parent
868180eb28
commit
cabd08f0ec
@@ -1,10 +1,19 @@
|
||||
import type { Mock } from 'vitest'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { api } from '@/scripts/api'
|
||||
|
||||
interface MockWebSocket {
|
||||
readyState: number
|
||||
send: Mock
|
||||
close: Mock
|
||||
addEventListener: Mock
|
||||
removeEventListener: Mock
|
||||
}
|
||||
|
||||
describe('API Feature Flags', () => {
|
||||
let mockWebSocket: any
|
||||
const wsEventHandlers: { [key: string]: (event: any) => void } = {}
|
||||
let mockWebSocket: MockWebSocket
|
||||
const wsEventHandlers: { [key: string]: (event: unknown) => void } = {}
|
||||
|
||||
beforeEach(() => {
|
||||
// Use fake timers
|
||||
@@ -16,7 +25,7 @@ describe('API Feature Flags', () => {
|
||||
send: vi.fn(),
|
||||
close: vi.fn(),
|
||||
addEventListener: vi.fn(
|
||||
(event: string, handler: (event: any) => void) => {
|
||||
(event: string, handler: (event: unknown) => void) => {
|
||||
wsEventHandlers[event] = handler
|
||||
}
|
||||
),
|
||||
|
||||
@@ -919,8 +919,7 @@ export class ComfyApp {
|
||||
const nodeDefArray: ComfyNodeDefV1[] = Object.values(allNodeDefs)
|
||||
useExtensionService().invokeExtensions(
|
||||
'beforeRegisterVueAppNodeDefs',
|
||||
nodeDefArray,
|
||||
this
|
||||
nodeDefArray
|
||||
)
|
||||
nodeDefStore.updateNodeDefs(nodeDefArray)
|
||||
}
|
||||
|
||||
@@ -72,7 +72,11 @@ const findIsobmffBoxByType = (
|
||||
return null
|
||||
}
|
||||
|
||||
const extractJson = (data: Uint8Array, start: number, end: number): any => {
|
||||
const extractJson = (
|
||||
data: Uint8Array,
|
||||
start: number,
|
||||
end: number
|
||||
): ComfyWorkflowJSON | ComfyApiWorkflow | null => {
|
||||
let jsonStart = start
|
||||
while (jsonStart < end && data[jsonStart] !== ASCII.OPEN_BRACE) {
|
||||
jsonStart++
|
||||
@@ -133,7 +137,7 @@ const extractMetadataValueFromDataBox = (
|
||||
lowerKeyName === ComfyMetadataTags.PROMPT.toLowerCase() ||
|
||||
lowerKeyName === ComfyMetadataTags.WORKFLOW.toLowerCase()
|
||||
) {
|
||||
return extractJson(data, valueStart, dataBoxEnd) || null
|
||||
return extractJson(data, valueStart, dataBoxEnd)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ type Props = {
|
||||
style?: Partial<CSSStyleDeclaration>
|
||||
for?: string
|
||||
textContent?: string
|
||||
[key: string]: any
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
type Children = Element[] | Element | string | string[]
|
||||
|
||||
Reference in New Issue
Block a user