mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-20 14:30:41 +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>
174 lines
5.0 KiB
TypeScript
174 lines
5.0 KiB
TypeScript
import { fromPartial } from '@total-typescript/shoehorn'
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
import type { NodeExecutionOutput } from '@/schemas/apiSchema'
|
|
import { parseNodeOutput, parseTaskOutput } from '@/stores/resultItemParsing'
|
|
|
|
function makeOutput(
|
|
overrides: Partial<NodeExecutionOutput> = {}
|
|
): NodeExecutionOutput {
|
|
return { ...overrides }
|
|
}
|
|
|
|
describe(parseNodeOutput, () => {
|
|
it('returns empty array for output with no known media types', () => {
|
|
const result = parseNodeOutput('1', makeOutput({ text: '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 = parseNodeOutput('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 = parseNodeOutput(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 = parseNodeOutput('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 = parseNodeOutput('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 = parseNodeOutput('1', output)
|
|
expect(result).toEqual([])
|
|
})
|
|
|
|
it('excludes animated key', () => {
|
|
const output = makeOutput({
|
|
images: [{ filename: 'img.png', subfolder: '', type: 'output' }],
|
|
animated: [true]
|
|
})
|
|
|
|
const result = parseNodeOutput('1', output)
|
|
|
|
expect(result).toHaveLength(1)
|
|
expect(result[0].mediaType).toBe('images')
|
|
})
|
|
|
|
it('excludes text key', () => {
|
|
const output = makeOutput({
|
|
images: [{ filename: 'img.png', subfolder: '', type: 'output' }],
|
|
text: 'some text output'
|
|
})
|
|
|
|
const result = parseNodeOutput('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 = parseNodeOutput('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 = parseNodeOutput('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 = parseNodeOutput('1', output)
|
|
|
|
expect(result).toHaveLength(1)
|
|
expect(result[0].filename).toBe('valid.png')
|
|
})
|
|
})
|
|
|
|
describe(parseTaskOutput, () => {
|
|
it('flattens across multiple nodes', () => {
|
|
const taskOutput: Record<string, NodeExecutionOutput> = {
|
|
'1': makeOutput({
|
|
images: [{ filename: 'a.png', subfolder: '', type: 'output' }]
|
|
}),
|
|
'2': makeOutput({
|
|
audio: [{ filename: 'b.wav', subfolder: '', type: 'output' }]
|
|
})
|
|
}
|
|
|
|
const result = parseTaskOutput(taskOutput)
|
|
|
|
expect(result).toHaveLength(2)
|
|
expect(result[0].nodeId).toBe('1')
|
|
expect(result[0].filename).toBe('a.png')
|
|
expect(result[1].nodeId).toBe('2')
|
|
expect(result[1].filename).toBe('b.wav')
|
|
})
|
|
})
|