mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-20 14:30:41 +00:00
## Summary - Convert `fromAny` → `fromPartial` in 7 test files where object literals or interfaces are passed - `fromPartial` type-checks the provided fields, unlike `fromAny` which bypasses all checking (same as `as unknown as`) - Class-based types (`LGraphNode`, `LGraph`) remain `fromAny` due to shoehorn's `PartialDeep` incompatibility with class constructors ## Changes - **Pure conversions** (all `fromAny` → `fromPartial`): `domWidgetZIndex`, `matchPromotedInput`, `promotionUtils`, `subgraphNavigationStore` - **Mixed** (some converted, some kept): `promotedWidgetView`, `widgetUtil` - **Cleanup**: `nodeOutputStore` type param normalization Follows up on #10761. ## Test plan - [x] `pnpm typecheck` passes - [x] `pnpm vitest run` on all 7 changed files — 169 tests pass - [x] `pnpm lint` passes ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-10788-test-migrate-fromAny-to-fromPartial-for-type-checked-test-mocks-3356d73d365081f7bf61d48a47af530c) by [Unito](https://www.unito.io)
82 lines
1.9 KiB
TypeScript
82 lines
1.9 KiB
TypeScript
import { fromPartial } from '@total-typescript/shoehorn'
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets'
|
|
import { matchPromotedInput } from './matchPromotedInput'
|
|
|
|
type MockInput = {
|
|
name: string
|
|
_widget?: IBaseWidget
|
|
}
|
|
|
|
function createWidget(name: string): IBaseWidget {
|
|
return {
|
|
name,
|
|
type: 'text'
|
|
} as IBaseWidget
|
|
}
|
|
|
|
describe(matchPromotedInput, () => {
|
|
it('prefers exact _widget matches before same-name inputs', () => {
|
|
const targetWidget = createWidget('seed')
|
|
const aliasWidget = createWidget('seed')
|
|
|
|
const aliasInput: MockInput = {
|
|
name: 'seed',
|
|
_widget: aliasWidget
|
|
}
|
|
const exactInput: MockInput = {
|
|
name: 'seed',
|
|
_widget: targetWidget
|
|
}
|
|
|
|
const matched = matchPromotedInput(
|
|
fromPartial<
|
|
Array<{
|
|
name: string
|
|
_widget?: IBaseWidget
|
|
}>
|
|
>([aliasInput, exactInput]),
|
|
targetWidget
|
|
)
|
|
|
|
expect(matched).toBe(exactInput)
|
|
})
|
|
|
|
it('falls back to same-name matching when no exact widget match exists', () => {
|
|
const targetWidget = createWidget('seed')
|
|
const aliasInput: MockInput = {
|
|
name: 'seed'
|
|
}
|
|
|
|
const matched = matchPromotedInput(
|
|
fromPartial<Array<{ name: string; _widget?: IBaseWidget }>>([aliasInput]),
|
|
targetWidget
|
|
)
|
|
|
|
expect(matched).toBe(aliasInput)
|
|
})
|
|
|
|
it('does not guess when multiple same-name inputs exist without an exact match', () => {
|
|
const targetWidget = createWidget('seed')
|
|
const firstAliasInput: MockInput = {
|
|
name: 'seed'
|
|
}
|
|
const secondAliasInput: MockInput = {
|
|
name: 'seed'
|
|
}
|
|
|
|
const matched = matchPromotedInput(
|
|
fromPartial<
|
|
Array<{
|
|
name: string
|
|
_widget?: IBaseWidget
|
|
}>
|
|
>([firstAliasInput, secondAliasInput]),
|
|
targetWidget
|
|
)
|
|
|
|
expect(matched).toBeUndefined()
|
|
})
|
|
})
|