mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-02-13 15:02:37 +08:00
Refactored and extended test
This commit is contained in:
parent
be191b1489
commit
a2fafda0e0
@ -13,49 +13,70 @@ afterEach(() => {
|
|||||||
jest.resetModules();
|
jest.resetModules();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("widget conversion + primitive works on all standard types", async () => {
|
[
|
||||||
/**
|
{ name: "int", type: "INT", widget: "number", control: true },
|
||||||
* Test node with widgets of each type
|
{ name: "float", type: "FLOAT", widget: "number", control: true },
|
||||||
* @type { import("../../web/types/comfy").ComfyObjectInfo } ComfyObjectInfo
|
{ name: "text", type: "STRING" },
|
||||||
*/
|
{
|
||||||
const WidgetTestNode = {
|
name: "customtext",
|
||||||
category: "test",
|
type: "STRING",
|
||||||
name: "WidgetTestNode",
|
opt: { multiline: true },
|
||||||
output_name: [],
|
},
|
||||||
input: {
|
{ name: "toggle", type: "BOOLEAN" },
|
||||||
required: {
|
{ name: "combo", type: ["a", "b", "c"], control: true },
|
||||||
int: ["INT", {}],
|
].forEach((c) => {
|
||||||
float: ["FLOAT", {}],
|
test(`widget conversion + primitive works on ${c.name}`, async () => {
|
||||||
text: ["STRING", {}],
|
/**
|
||||||
multiline: ["STRING", { multiline: true }],
|
* Test node with widgets of each type
|
||||||
bool: ["BOOLEAN", {}],
|
* @type { import("../../web/types/comfy").ComfyObjectInfo } ComfyObjectInfo
|
||||||
combo: [["a", "b", "c"], {}],
|
*/
|
||||||
|
const WidgetTestNode = {
|
||||||
|
category: "test",
|
||||||
|
name: "WidgetTestNode",
|
||||||
|
output_name: [],
|
||||||
|
input: {
|
||||||
|
required: {
|
||||||
|
[c.name]: [c.type, c.opt ?? {}],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
};
|
||||||
};
|
|
||||||
|
|
||||||
const { graph, ez } = await start({
|
const { ez } = await start({
|
||||||
mockNodeDefs: {
|
mockNodeDefs: {
|
||||||
WidgetTestNode,
|
WidgetTestNode,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const n = ez.WidgetTestNode();
|
// Create test node and convert to input
|
||||||
|
const n = ez.WidgetTestNode();
|
||||||
for (const name in WidgetTestNode.input?.required) {
|
const w = n.widgets[c.name];
|
||||||
const w = n.widgets[name];
|
|
||||||
w.convertToInput();
|
w.convertToInput();
|
||||||
expect(w.isConvertedToInput).toBeTruthy();
|
expect(w.isConvertedToInput).toBeTruthy();
|
||||||
const input = w.getConvertedInput();
|
const input = w.getConvertedInput();
|
||||||
expect(input).toBeTruthy();
|
expect(input).toBeTruthy();
|
||||||
|
|
||||||
|
// Connect to primitive
|
||||||
const p1 = ez.PrimitiveNode();
|
const p1 = ez.PrimitiveNode();
|
||||||
// @ts-ignore : input is valid
|
// @ts-ignore : input is valid
|
||||||
p1.outputs[0].connectTo(input);
|
p1.outputs[0].connectTo(input);
|
||||||
expect(p1.outputs[0].connectTo).toHaveLength(1);
|
expect(p1.outputs[0].connectTo).toHaveLength(1);
|
||||||
}
|
|
||||||
|
// Ensure widget is correct type
|
||||||
|
const valueWidget = p1.widgets.value;
|
||||||
|
expect(valueWidget.widget.type).toBe(c.widget ?? c.name);
|
||||||
|
|
||||||
|
// Check if control_after_generate should be added
|
||||||
|
if (c.control) {
|
||||||
|
const controlWidget = p1.widgets.control_after_generate;
|
||||||
|
expect(controlWidget.widget.type).toBe("combo");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure we dont have other widgets
|
||||||
|
expect(p1.node.widgets).toHaveLength(1 + +!!c.control);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
test("converted widget works after reload", async () => {
|
test("converted widget works after reload", async () => {
|
||||||
const { graph, ez } = await start();
|
const { graph, ez } = await start();
|
||||||
let n = ez.CheckpointLoaderSimple();
|
let n = ez.CheckpointLoaderSimple();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user