mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-19 13:59:28 +00:00
*PR Created by the Glary-Bot Agent* --- ## Summary - Replace all `as unknown as Type` assertions in 59 unit test files with type-safe `@total-typescript/shoehorn` functions - Use `fromPartial<Type>()` for partial mock objects where deep-partial type-checks (21 files) - Use `fromAny<Type>()` for fundamentally incompatible types: null, undefined, primitives, variables, class expressions, and mocks with test-specific extra properties that `PartialDeepObject` rejects (remaining files) - All explicit type parameters preserved so TypeScript return types are correct - Browser test `.spec.ts` files excluded (shoehorn unavailable in `page.evaluate` browser context) ## Verification - `pnpm typecheck` ✅ - `pnpm lint` ✅ - `pnpm format` ✅ - Pre-commit hooks passed (format + oxlint + eslint + typecheck) - Migrated test files verified passing (ran representative subset) - No test behavior changes — only type assertion syntax changed - No UI changes — screenshots not applicable ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-10761-test-migrate-as-unknown-as-to-total-typescript-shoehorn-3336d73d365081f6b8adc44db5dcc380) by [Unito](https://www.unito.io) --------- Co-authored-by: Glary-Bot <glary-bot@users.noreply.github.com> Co-authored-by: Amp <amp@ampcode.com>
86 lines
1.9 KiB
TypeScript
86 lines
1.9 KiB
TypeScript
import { fromAny } 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(
|
|
fromAny<
|
|
Array<{
|
|
name: string
|
|
_widget?: IBaseWidget
|
|
}>,
|
|
unknown
|
|
>([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(
|
|
fromAny<Array<{ name: string; _widget?: IBaseWidget }>, unknown>([
|
|
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(
|
|
fromAny<
|
|
Array<{
|
|
name: string
|
|
_widget?: IBaseWidget
|
|
}>,
|
|
unknown
|
|
>([firstAliasInput, secondAliasInput]),
|
|
targetWidget
|
|
)
|
|
|
|
expect(matched).toBeUndefined()
|
|
})
|
|
})
|