mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-20 06:20:11 +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>
156 lines
4.7 KiB
TypeScript
156 lines
4.7 KiB
TypeScript
import { fromPartial } from '@total-typescript/shoehorn'
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
import { flattenNodeOutput } from '@/renderer/extensions/linearMode/flattenNodeOutput'
|
|
import type { NodeExecutionOutput } from '@/schemas/apiSchema'
|
|
|
|
function makeOutput(
|
|
overrides: Partial<NodeExecutionOutput> = {}
|
|
): NodeExecutionOutput {
|
|
return { ...overrides }
|
|
}
|
|
|
|
describe(flattenNodeOutput, () => {
|
|
it('returns empty array for output with no known media types', () => {
|
|
const result = flattenNodeOutput(['1', makeOutput({ unknown: 'hello' })])
|
|
expect(result).toEqual([])
|
|
})
|
|
|
|
it('flattens images into ResultItemImpl instances', () => {
|
|
const output = makeOutput({
|
|
images: [
|
|
{ filename: 'a.png', subfolder: '', type: 'output' },
|
|
{ filename: 'b.png', subfolder: 'sub', type: 'output' }
|
|
]
|
|
})
|
|
|
|
const result = flattenNodeOutput(['42', output])
|
|
|
|
expect(result).toHaveLength(2)
|
|
expect(result[0].filename).toBe('a.png')
|
|
expect(result[0].nodeId).toBe('42')
|
|
expect(result[0].mediaType).toBe('images')
|
|
expect(result[1].filename).toBe('b.png')
|
|
expect(result[1].subfolder).toBe('sub')
|
|
})
|
|
|
|
it('flattens audio outputs', () => {
|
|
const output = makeOutput({
|
|
audio: [{ filename: 'sound.wav', subfolder: '', type: 'output' }]
|
|
})
|
|
|
|
const result = flattenNodeOutput([7, output])
|
|
|
|
expect(result).toHaveLength(1)
|
|
expect(result[0].mediaType).toBe('audio')
|
|
expect(result[0].nodeId).toBe(7)
|
|
})
|
|
|
|
it('flattens multiple media types in a single output', () => {
|
|
const output = makeOutput({
|
|
images: [{ filename: 'img.png', subfolder: '', type: 'output' }],
|
|
video: [{ filename: 'vid.mp4', subfolder: '', type: 'output' }]
|
|
})
|
|
|
|
const result = flattenNodeOutput(['1', output])
|
|
|
|
expect(result).toHaveLength(2)
|
|
const types = result.map((r) => r.mediaType)
|
|
expect(types).toContain('images')
|
|
expect(types).toContain('video')
|
|
})
|
|
|
|
it('handles gifs and 3d output types', () => {
|
|
const output = makeOutput({
|
|
gifs: [
|
|
{ filename: 'anim.gif', subfolder: '', type: 'output' }
|
|
] as NodeExecutionOutput['gifs'],
|
|
'3d': [
|
|
{ filename: 'model.glb', subfolder: '', type: 'output' }
|
|
] as NodeExecutionOutput['3d']
|
|
})
|
|
|
|
const result = flattenNodeOutput(['5', output])
|
|
|
|
expect(result).toHaveLength(2)
|
|
const types = result.map((r) => r.mediaType)
|
|
expect(types).toContain('gifs')
|
|
expect(types).toContain('3d')
|
|
})
|
|
|
|
it('ignores empty arrays', () => {
|
|
const output = makeOutput({ images: [], audio: [] })
|
|
const result = flattenNodeOutput(['1', output])
|
|
expect(result).toEqual([])
|
|
})
|
|
|
|
it('flattens non-standard output keys with ResultItem-like values', () => {
|
|
const output = makeOutput(
|
|
fromPartial<NodeExecutionOutput>({
|
|
a_images: [{ filename: 'before.png', subfolder: '', type: 'output' }],
|
|
b_images: [{ filename: 'after.png', subfolder: '', type: 'output' }]
|
|
})
|
|
)
|
|
|
|
const result = flattenNodeOutput(['10', output])
|
|
|
|
expect(result).toHaveLength(2)
|
|
expect(result.map((r) => r.filename)).toContain('before.png')
|
|
expect(result.map((r) => r.filename)).toContain('after.png')
|
|
})
|
|
|
|
it('excludes animated key', () => {
|
|
const output = makeOutput({
|
|
images: [{ filename: 'img.png', subfolder: '', type: 'output' }],
|
|
animated: [true]
|
|
})
|
|
|
|
const result = flattenNodeOutput(['1', output])
|
|
|
|
expect(result).toHaveLength(1)
|
|
expect(result[0].mediaType).toBe('images')
|
|
})
|
|
|
|
it('excludes non-ResultItem array items', () => {
|
|
const output = fromPartial<NodeExecutionOutput>({
|
|
images: [{ filename: 'img.png', subfolder: '', type: 'output' }],
|
|
custom_data: [{ randomKey: 123 }]
|
|
})
|
|
|
|
const result = flattenNodeOutput(['1', output])
|
|
|
|
expect(result).toHaveLength(1)
|
|
expect(result[0].mediaType).toBe('images')
|
|
})
|
|
|
|
it('accepts items with filename but no subfolder', () => {
|
|
const output = fromPartial<NodeExecutionOutput>({
|
|
images: [
|
|
{ filename: 'valid.png', subfolder: '', type: 'output' },
|
|
{ filename: 'no-subfolder.png' }
|
|
]
|
|
})
|
|
|
|
const result = flattenNodeOutput(['1', output])
|
|
|
|
expect(result).toHaveLength(2)
|
|
expect(result[0].filename).toBe('valid.png')
|
|
expect(result[1].filename).toBe('no-subfolder.png')
|
|
expect(result[1].subfolder).toBe('')
|
|
})
|
|
|
|
it('excludes items missing filename', () => {
|
|
const output = fromPartial<NodeExecutionOutput>({
|
|
images: [
|
|
{ filename: 'valid.png', subfolder: '', type: 'output' },
|
|
{ subfolder: '', type: 'output' }
|
|
]
|
|
})
|
|
|
|
const result = flattenNodeOutput(['1', output])
|
|
|
|
expect(result).toHaveLength(1)
|
|
expect(result[0].filename).toBe('valid.png')
|
|
})
|
|
})
|