mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-22 13:32:11 +00:00
fix(ext-api/tests): TypeScript cleanup in lazy-serialize.v1
- Add V1Widget interface for proper typing - Remove unused imports Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,20 +3,22 @@
|
||||
// Source: research/architecture/widget-serialization-state.md §1a
|
||||
// Cross-ref: S4.W3 (widget.serializeValue assignment), BC.12
|
||||
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
||||
import {
|
||||
createMiniComfyApp,
|
||||
loadEvidenceSnippet,
|
||||
countEvidenceExcerpts,
|
||||
runV1
|
||||
} from '@/extension-api-v2/harness'
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { loadEvidenceSnippet, countEvidenceExcerpts } from '@/extension-api-v2/harness'
|
||||
|
||||
// v1 widget shape with serializeValue
|
||||
interface V1Widget {
|
||||
name: string
|
||||
value: unknown
|
||||
serializeValue?: (node: unknown, index: number) => unknown
|
||||
options: Record<string, unknown>
|
||||
}
|
||||
|
||||
describe('I-WS.4 v1 contract — sync serializeValue for shimmed widgets', () => {
|
||||
describe('(a) v1 sync serializeValue still works', () => {
|
||||
it('sync serializeValue function assigned to widget is called during serialization', () => {
|
||||
// Mock: widget with sync serializeValue
|
||||
const serializeFn = vi.fn(() => 'transformed-value')
|
||||
const widget = {
|
||||
const widget: V1Widget = {
|
||||
name: 'test_widget',
|
||||
value: 'original-value',
|
||||
serializeValue: serializeFn,
|
||||
@@ -33,7 +35,7 @@ describe('I-WS.4 v1 contract — sync serializeValue for shimmed widgets', () =>
|
||||
})
|
||||
|
||||
it('sync serializeValue return value replaces widget.value in serialized output', () => {
|
||||
const widget = {
|
||||
const widget: V1Widget = {
|
||||
name: 'seed',
|
||||
value: 12345,
|
||||
serializeValue: () => 'resolved-seed-42',
|
||||
@@ -51,20 +53,20 @@ describe('I-WS.4 v1 contract — sync serializeValue for shimmed widgets', () =>
|
||||
it('sync serializeValue receives node and positional index arguments', () => {
|
||||
const serializeFn = vi.fn(() => 'value')
|
||||
const mockNode = { id: 42, type: 'TestNode' }
|
||||
const widget = {
|
||||
const widget: V1Widget = {
|
||||
name: 'test',
|
||||
value: 0,
|
||||
serializeValue: serializeFn,
|
||||
options: {}
|
||||
}
|
||||
|
||||
widget.serializeValue(mockNode, 3)
|
||||
widget.serializeValue?.(mockNode, 3)
|
||||
|
||||
expect(serializeFn).toHaveBeenCalledWith(mockNode, 3)
|
||||
})
|
||||
|
||||
it('when serializeValue not assigned, widget.value is used directly', () => {
|
||||
const widget = {
|
||||
const widget: V1Widget = {
|
||||
name: 'plain_widget',
|
||||
value: 'direct-value',
|
||||
options: {}
|
||||
@@ -98,7 +100,7 @@ describe('I-WS.4 v1 contract — sync serializeValue for shimmed widgets', () =>
|
||||
describe('serialize===false widgets in v1', () => {
|
||||
it('widget with options.serialize===false still has serializeValue called', () => {
|
||||
const serializeFn = vi.fn(() => 'hidden-value')
|
||||
const widget = {
|
||||
const widget: V1Widget = {
|
||||
name: 'control_after_generate',
|
||||
value: 'fixed',
|
||||
serializeValue: serializeFn,
|
||||
|
||||
Reference in New Issue
Block a user