From c4fe7e0bf1f5bbc89b0504bc2169fe3a9acb4f69 Mon Sep 17 00:00:00 2001 From: space-nuko <24979496+space-nuko@users.noreply.github.com> Date: Sun, 21 May 2023 18:00:27 -0500 Subject: [PATCH] Convert vanilla workflow tests --- src/lib/components/ComfyApp.ts | 2 -- src/tests/convertVanillaWorkflowTests.ts | 41 ++++++++++++++++++++++++ src/tests/data/objectInfo.json | 1 + src/tests/testSuite.ts | 1 + 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 src/tests/convertVanillaWorkflowTests.ts create mode 100644 src/tests/data/objectInfo.json diff --git a/src/lib/components/ComfyApp.ts b/src/lib/components/ComfyApp.ts index 331e26c..64d0a97 100644 --- a/src/lib/components/ComfyApp.ts +++ b/src/lib/components/ComfyApp.ts @@ -166,7 +166,6 @@ function isVanillaWorkflow(data: any): data is SerializedLGraph { } type BackendNodeDef = { - ctor: new (title?: string) => ComfyBackendNode, nodeDef: ComfyNodeDef } @@ -358,7 +357,6 @@ export default class ComfyApp { LiteGraph.registerNodeType(node); node.category = nodeDef.category; ComfyApp.knownBackendNodes[nodeId] = { - ctor, nodeDef } diff --git a/src/tests/convertVanillaWorkflowTests.ts b/src/tests/convertVanillaWorkflowTests.ts new file mode 100644 index 0000000..5ef4c1b --- /dev/null +++ b/src/tests/convertVanillaWorkflowTests.ts @@ -0,0 +1,41 @@ +import { expect } from 'vitest'; +import UnitTest from "./UnitTest"; +import { readFile } from "fs/promises" +import { get } from "svelte/store"; +import convertVanillaWorkflow, { type ComfyVanillaWorkflow } from '$lib/convertVanillaWorkflow'; +import type { WorkflowAttributes } from '$lib/stores/workflowState'; +import { defaultWorkflowAttributes, type IDragItem, type WidgetLayout } from '$lib/stores/layoutStates'; +import ComfyApp from '$lib/components/ComfyApp'; +import { LiteGraph } from '@litegraph-ts/core'; +import type { ComfyNodeDef } from '$lib/ComfyNodeDef'; + +const objectInfo: Record = await import("./data/objectInfo.json") +const json1: ComfyVanillaWorkflow = await import("./data/convertedWidgetAndPrimitiveNode.json") + +export default class convertVanillaWorkflowTests extends UnitTest { + test__convertsPrimitiveNodeAndConvertedInput() { + const workflow = LiteGraph.cloneObject(json1) + const attrs: WorkflowAttributes = { ...defaultWorkflowAttributes } + + const converted = convertVanillaWorkflow(workflow, attrs) + + ComfyApp.knownBackendNodes["KSampler"] = { + nodeDef: objectInfo["KSampler"] + } + + expect(converted).toBeInstanceOf(Array) + + const [convWorkflow, convLayout] = converted; + + const layout = get(convLayout) + + expect(Object.keys(layout.allItems)).toHaveLength(4) + + const widget = Object.values(layout.allItems).find(di => di.dragItem.type === "widget")?.dragItem as WidgetLayout; + expect(widget).toBeDefined(); + expect(widget.attrs.title).toEqual("cfg") + expect(widget.node).toBeDefined(); + expect(widget.node.type).toEqual("ui/number") + expect(convWorkflow.graph.getNodeById(widget.node.id)).toEqual(widget.node) + } +} diff --git a/src/tests/data/objectInfo.json b/src/tests/data/objectInfo.json new file mode 100644 index 0000000..d3888e2 --- /dev/null +++ b/src/tests/data/objectInfo.json @@ -0,0 +1 @@ +{"KSampler":{"input":{"required":{"model":["MODEL"],"seed":["INT",{"default":0,"min":0,"max":18446744073709552000}],"steps":["INT",{"default":20,"min":1,"max":10000}],"cfg":["FLOAT",{"default":8,"min":0,"max":100}],"sampler_name":[["euler","euler_ancestral","heun","dpm_2","dpm_2_ancestral","lms","dpm_fast","dpm_adaptive","dpmpp_2s_ancestral","dpmpp_sde","dpmpp_2m","ddim","uni_pc","uni_pc_bh2"]],"scheduler":[["normal","karras","simple","ddim_uniform"]],"positive":["CONDITIONING"],"negative":["CONDITIONING"],"latent_image":["LATENT"],"denoise":["FLOAT",{"default":1,"min":0,"max":1,"step":0.01}]}},"output":["LATENT"],"output_is_list":[false],"output_name":["LATENT"],"name":"KSampler","display_name":"KSampler","description":"","category":"sampling"}} diff --git a/src/tests/testSuite.ts b/src/tests/testSuite.ts index 3d067bd..9e96316 100644 --- a/src/tests/testSuite.ts +++ b/src/tests/testSuite.ts @@ -2,3 +2,4 @@ export { default as ComfyPromptSerializerTests } from "./ComfyPromptSerializerTe export { default as ComfyGraphTests } from "./ComfyGraphTests" export { default as parseA1111Tests } from "./parseA1111Tests" export { default as convertA1111ToStdPromptTests } from "./convertA1111ToStdPromptTests" +export { default as convertVanillaWorkflowTest } from "./convertVanillaWorkflowTests"