diff --git a/test/ConfigureGraph.test.ts b/test/ConfigureGraph.test.ts new file mode 100644 index 000000000..c2c3e3487 --- /dev/null +++ b/test/ConfigureGraph.test.ts @@ -0,0 +1,15 @@ +import { describe } from "vitest" +import { LGraph } from "@/litegraph" +import { dirtyTest } from "./testExtensions" + +describe("LGraph configure()", () => { + dirtyTest("LGraph matches previous snapshot (normal configure() usage)", ({ expect, minimalSerialisableGraph, basicSerialisableGraph }) => { + const configuredMinGraph = new LGraph() + configuredMinGraph.configure(minimalSerialisableGraph) + expect(configuredMinGraph).toMatchSnapshot("configuredMinGraph") + + const configuredBasicGraph = new LGraph() + configuredBasicGraph.configure(basicSerialisableGraph) + expect(configuredBasicGraph).toMatchSnapshot("configuredBasicGraph") + }) +}) diff --git a/test/LGraph.test.ts b/test/LGraph.test.ts index 42f174111..a490784c7 100644 --- a/test/LGraph.test.ts +++ b/test/LGraph.test.ts @@ -2,7 +2,7 @@ import { describe } from "vitest" import { LGraph, LiteGraph } from "@/litegraph" import { test } from "./testExtensions" -describe.concurrent("LGraph", () => { +describe("LGraph", () => { test("can be instantiated", ({ expect }) => { // @ts-expect-error Intentional - extra holds any / all consumer data that should be serialised const graph = new LGraph({ extra: "TestGraph" }) @@ -11,6 +11,14 @@ describe.concurrent("LGraph", () => { expect(graph.extra).toBe("TestGraph") }) + test("is exactly the same type", async ({ expect }) => { + const directImport = await import("@/LGraph") + const entryPointImport = await import("@/litegraph") + + expect(LiteGraph.LGraph).toBe(directImport.LGraph) + expect(LiteGraph.LGraph).toBe(entryPointImport.LGraph) + }) + test("populates optional values", ({ expect, minimalSerialisableGraph }) => { const dGraph = new LGraph(minimalSerialisableGraph) expect(dGraph.links).toBeInstanceOf(Map) @@ -18,20 +26,13 @@ describe.concurrent("LGraph", () => { expect(dGraph.groups).toBeInstanceOf(Array) }) - test("matches previous snapshot", ({ expect, minimalSerialisableGraph, basicSerialisableGraph }) => { - const minLGraph = new LGraph(minimalSerialisableGraph) - expect(minLGraph).toMatchSnapshot("minLGraph") - const basicLGraph = new LGraph(basicSerialisableGraph) - expect(basicLGraph).toMatchSnapshot("basicLGraph") - }) - test("supports schema v0.4 graphs", ({ expect, oldSchemaGraph }) => { const fromOldSchema = new LGraph(oldSchemaGraph) expect(fromOldSchema).toMatchSnapshot("oldSchemaGraph") }) }) -describe.concurrent("Legacy LGraph Compatibility Layer", () => { +describe("Legacy LGraph Compatibility Layer", () => { test("can be extended via prototype", ({ expect, minimalGraph }) => { // @ts-expect-error Should always be an error. LGraph.prototype.newMethod = function () { diff --git a/test/LGraph_constructor.test.ts b/test/LGraph_constructor.test.ts new file mode 100644 index 000000000..a5195ef8e --- /dev/null +++ b/test/LGraph_constructor.test.ts @@ -0,0 +1,13 @@ +import { describe } from "vitest" +import { LGraph } from "@/litegraph" +import { dirtyTest } from "./testExtensions" + +describe("LGraph (constructor only)", () => { + dirtyTest("Matches previous snapshot", ({ expect, minimalSerialisableGraph, basicSerialisableGraph }) => { + const minLGraph = new LGraph(minimalSerialisableGraph) + expect(minLGraph).toMatchSnapshot("minLGraph") + + const basicLGraph = new LGraph(basicSerialisableGraph) + expect(basicLGraph).toMatchSnapshot("basicLGraph") + }) +}) diff --git a/test/__snapshots__/ConfigureGraph.test.ts.snap b/test/__snapshots__/ConfigureGraph.test.ts.snap new file mode 100644 index 000000000..1f7a5ebf0 --- /dev/null +++ b/test/__snapshots__/ConfigureGraph.test.ts.snap @@ -0,0 +1,315 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`LGraph configure() > LGraph matches previous snapshot (normal configure() usage) > configuredBasicGraph 1`] = ` +LGraph { + "_groups": [ + LGraphGroup { + "_bounding": Float32Array [ + 20, + 20, + 1, + 3, + ], + "_children": Set {}, + "_nodes": [], + "_pos": Float32Array [ + 20, + 20, + ], + "_size": Float32Array [ + 1, + 3, + ], + "color": "#6029aa", + "flags": {}, + "font": undefined, + "font_size": 14, + "graph": [Circular], + "id": 123, + "isPointInside": [Function], + "selected": undefined, + "setDirtyCanvas": [Function], + "title": "A group to test with", + }, + ], + "_input_nodes": undefined, + "_last_trigger_time": undefined, + "_links": Map {}, + "_nodes": [ + LGraphNode { + "_collapsed_width": undefined, + "_level": undefined, + "_pos": Float32Array [ + 10, + 10, + ], + "_posSize": Float32Array [ + 10, + 10, + 140, + 60, + ], + "_relative_id": undefined, + "_shape": undefined, + "_size": Float32Array [ + 140, + 60, + ], + "action_call": undefined, + "action_triggered": undefined, + "badgePosition": "top-left", + "badges": [], + "bgcolor": undefined, + "block_delete": undefined, + "boxcolor": undefined, + "clip_area": undefined, + "clonable": undefined, + "color": undefined, + "connections": [], + "console": undefined, + "exec_version": undefined, + "execute_triggered": undefined, + "flags": {}, + "freeWidgetSpace": undefined, + "gotFocusAt": undefined, + "graph": [Circular], + "has_errors": undefined, + "id": 1, + "ignore_remove": undefined, + "inputs": [], + "last_serialization": undefined, + "locked": undefined, + "lostFocusAt": undefined, + "mode": 0, + "mouseOver": undefined, + "optional_inputs": undefined, + "optional_outputs": undefined, + "order": 0, + "outputs": [], + "properties": {}, + "properties_info": [], + "redraw_on_mouse": undefined, + "removable": undefined, + "resizable": undefined, + "selected": undefined, + "serialize_widgets": undefined, + "showAdvanced": undefined, + "title": "LGraphNode", + "type": "mustBeSet", + "widgets": undefined, + "widgets_start_y": undefined, + "widgets_up": undefined, + }, + ], + "_nodes_by_id": { + "1": LGraphNode { + "_collapsed_width": undefined, + "_level": undefined, + "_pos": Float32Array [ + 10, + 10, + ], + "_posSize": Float32Array [ + 10, + 10, + 140, + 60, + ], + "_relative_id": undefined, + "_shape": undefined, + "_size": Float32Array [ + 140, + 60, + ], + "action_call": undefined, + "action_triggered": undefined, + "badgePosition": "top-left", + "badges": [], + "bgcolor": undefined, + "block_delete": undefined, + "boxcolor": undefined, + "clip_area": undefined, + "clonable": undefined, + "color": undefined, + "connections": [], + "console": undefined, + "exec_version": undefined, + "execute_triggered": undefined, + "flags": {}, + "freeWidgetSpace": undefined, + "gotFocusAt": undefined, + "graph": [Circular], + "has_errors": undefined, + "id": 1, + "ignore_remove": undefined, + "inputs": [], + "last_serialization": undefined, + "locked": undefined, + "lostFocusAt": undefined, + "mode": 0, + "mouseOver": undefined, + "optional_inputs": undefined, + "optional_outputs": undefined, + "order": 0, + "outputs": [], + "properties": {}, + "properties_info": [], + "redraw_on_mouse": undefined, + "removable": undefined, + "resizable": undefined, + "selected": undefined, + "serialize_widgets": undefined, + "showAdvanced": undefined, + "title": "LGraphNode", + "type": "mustBeSet", + "widgets": undefined, + "widgets_start_y": undefined, + "widgets_up": undefined, + }, + }, + "_nodes_executable": [], + "_nodes_in_order": [ + LGraphNode { + "_collapsed_width": undefined, + "_level": undefined, + "_pos": Float32Array [ + 10, + 10, + ], + "_posSize": Float32Array [ + 10, + 10, + 140, + 60, + ], + "_relative_id": undefined, + "_shape": undefined, + "_size": Float32Array [ + 140, + 60, + ], + "action_call": undefined, + "action_triggered": undefined, + "badgePosition": "top-left", + "badges": [], + "bgcolor": undefined, + "block_delete": undefined, + "boxcolor": undefined, + "clip_area": undefined, + "clonable": undefined, + "color": undefined, + "connections": [], + "console": undefined, + "exec_version": undefined, + "execute_triggered": undefined, + "flags": {}, + "freeWidgetSpace": undefined, + "gotFocusAt": undefined, + "graph": [Circular], + "has_errors": undefined, + "id": 1, + "ignore_remove": undefined, + "inputs": [], + "last_serialization": undefined, + "locked": undefined, + "lostFocusAt": undefined, + "mode": 0, + "mouseOver": undefined, + "optional_inputs": undefined, + "optional_outputs": undefined, + "order": 0, + "outputs": [], + "properties": {}, + "properties_info": [], + "redraw_on_mouse": undefined, + "removable": undefined, + "resizable": undefined, + "selected": undefined, + "serialize_widgets": undefined, + "showAdvanced": undefined, + "title": "LGraphNode", + "type": "mustBeSet", + "widgets": undefined, + "widgets_start_y": undefined, + "widgets_up": undefined, + }, + ], + "_version": 3, + "catch_errors": true, + "config": {}, + "elapsed_time": 0.01, + "errors_in_execution": undefined, + "execution_time": undefined, + "execution_timer_id": undefined, + "extra": {}, + "filter": undefined, + "fixedtime": 0, + "fixedtime_lapse": 0.01, + "globaltime": 0, + "inputs": {}, + "iteration": 0, + "last_update_time": 0, + "links": Map {}, + "list_of_graphcanvas": null, + "nodes_actioning": [], + "nodes_executedAction": [], + "nodes_executing": [], + "outputs": {}, + "runningtime": 0, + "starttime": 0, + "state": { + "lastGroupId": 123, + "lastLinkId": 0, + "lastNodeId": 1, + "lastRerouteId": 0, + }, + "status": 1, + "vars": {}, + "version": 1, +} +`; + +exports[`LGraph configure() > LGraph matches previous snapshot (normal configure() usage) > configuredMinGraph 1`] = ` +LGraph { + "_groups": [], + "_input_nodes": undefined, + "_last_trigger_time": undefined, + "_links": Map {}, + "_nodes": [], + "_nodes_by_id": {}, + "_nodes_executable": [], + "_nodes_in_order": [], + "_version": 0, + "catch_errors": true, + "config": {}, + "elapsed_time": 0.01, + "errors_in_execution": undefined, + "execution_time": undefined, + "execution_timer_id": undefined, + "extra": {}, + "filter": undefined, + "fixedtime": 0, + "fixedtime_lapse": 0.01, + "globaltime": 0, + "inputs": {}, + "iteration": 0, + "last_update_time": 0, + "links": Map {}, + "list_of_graphcanvas": null, + "nodes_actioning": [], + "nodes_executedAction": [], + "nodes_executing": [], + "outputs": {}, + "runningtime": 0, + "starttime": 0, + "state": { + "lastGroupId": 0, + "lastLinkId": 0, + "lastNodeId": 0, + "lastRerouteId": 0, + }, + "status": 1, + "vars": {}, + "version": 1, +} +`; diff --git a/test/__snapshots__/LGraph.test.ts.snap b/test/__snapshots__/LGraph.test.ts.snap index d941f203d..efa37d08b 100644 --- a/test/__snapshots__/LGraph.test.ts.snap +++ b/test/__snapshots__/LGraph.test.ts.snap @@ -1,325 +1,5 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`LGraph > matches previous snapshot > basicLGraph 1`] = ` -LGraph { - "_groups": [ - LGraphGroup { - "_bounding": Float32Array [ - 20, - 20, - 1, - 3, - ], - "_children": Set {}, - "_nodes": [], - "_pos": Float32Array [ - 20, - 20, - ], - "_size": Float32Array [ - 1, - 3, - ], - "color": "#6029aa", - "flags": {}, - "font": undefined, - "font_size": 14, - "graph": [Circular], - "id": 123, - "isPointInside": [Function], - "selected": undefined, - "setDirtyCanvas": [Function], - "title": "A group to test with", - }, - ], - "_input_nodes": undefined, - "_last_trigger_time": undefined, - "_links": Map {}, - "_nodes": [ - LGraphNode { - "_collapsed_width": undefined, - "_level": undefined, - "_pos": Float32Array [ - 10, - 10, - ], - "_posSize": Float32Array [ - 10, - 10, - 140, - 60, - ], - "_relative_id": undefined, - "_shape": undefined, - "_size": Float32Array [ - 140, - 60, - ], - "action_call": undefined, - "action_triggered": undefined, - "badgePosition": "top-left", - "badges": [], - "bgcolor": undefined, - "block_delete": undefined, - "boxcolor": undefined, - "clip_area": undefined, - "clonable": undefined, - "color": undefined, - "connections": [], - "console": undefined, - "exec_version": undefined, - "execute_triggered": undefined, - "flags": {}, - "freeWidgetSpace": undefined, - "gotFocusAt": undefined, - "graph": [Circular], - "has_errors": true, - "id": 1, - "ignore_remove": undefined, - "inputs": [], - "last_serialization": { - "id": 1, - }, - "locked": undefined, - "lostFocusAt": undefined, - "mode": undefined, - "mouseOver": undefined, - "optional_inputs": undefined, - "optional_outputs": undefined, - "order": 0, - "outputs": [], - "properties": {}, - "properties_info": [], - "redraw_on_mouse": undefined, - "removable": undefined, - "resizable": undefined, - "selected": undefined, - "serialize_widgets": undefined, - "showAdvanced": undefined, - "title": undefined, - "type": null, - "widgets": undefined, - "widgets_start_y": undefined, - "widgets_up": undefined, - }, - ], - "_nodes_by_id": { - "1": LGraphNode { - "_collapsed_width": undefined, - "_level": undefined, - "_pos": Float32Array [ - 10, - 10, - ], - "_posSize": Float32Array [ - 10, - 10, - 140, - 60, - ], - "_relative_id": undefined, - "_shape": undefined, - "_size": Float32Array [ - 140, - 60, - ], - "action_call": undefined, - "action_triggered": undefined, - "badgePosition": "top-left", - "badges": [], - "bgcolor": undefined, - "block_delete": undefined, - "boxcolor": undefined, - "clip_area": undefined, - "clonable": undefined, - "color": undefined, - "connections": [], - "console": undefined, - "exec_version": undefined, - "execute_triggered": undefined, - "flags": {}, - "freeWidgetSpace": undefined, - "gotFocusAt": undefined, - "graph": [Circular], - "has_errors": true, - "id": 1, - "ignore_remove": undefined, - "inputs": [], - "last_serialization": { - "id": 1, - }, - "locked": undefined, - "lostFocusAt": undefined, - "mode": undefined, - "mouseOver": undefined, - "optional_inputs": undefined, - "optional_outputs": undefined, - "order": 0, - "outputs": [], - "properties": {}, - "properties_info": [], - "redraw_on_mouse": undefined, - "removable": undefined, - "resizable": undefined, - "selected": undefined, - "serialize_widgets": undefined, - "showAdvanced": undefined, - "title": undefined, - "type": null, - "widgets": undefined, - "widgets_start_y": undefined, - "widgets_up": undefined, - }, - }, - "_nodes_executable": [], - "_nodes_in_order": [ - LGraphNode { - "_collapsed_width": undefined, - "_level": undefined, - "_pos": Float32Array [ - 10, - 10, - ], - "_posSize": Float32Array [ - 10, - 10, - 140, - 60, - ], - "_relative_id": undefined, - "_shape": undefined, - "_size": Float32Array [ - 140, - 60, - ], - "action_call": undefined, - "action_triggered": undefined, - "badgePosition": "top-left", - "badges": [], - "bgcolor": undefined, - "block_delete": undefined, - "boxcolor": undefined, - "clip_area": undefined, - "clonable": undefined, - "color": undefined, - "connections": [], - "console": undefined, - "exec_version": undefined, - "execute_triggered": undefined, - "flags": {}, - "freeWidgetSpace": undefined, - "gotFocusAt": undefined, - "graph": [Circular], - "has_errors": true, - "id": 1, - "ignore_remove": undefined, - "inputs": [], - "last_serialization": { - "id": 1, - }, - "locked": undefined, - "lostFocusAt": undefined, - "mode": undefined, - "mouseOver": undefined, - "optional_inputs": undefined, - "optional_outputs": undefined, - "order": 0, - "outputs": [], - "properties": {}, - "properties_info": [], - "redraw_on_mouse": undefined, - "removable": undefined, - "resizable": undefined, - "selected": undefined, - "serialize_widgets": undefined, - "showAdvanced": undefined, - "title": undefined, - "type": null, - "widgets": undefined, - "widgets_start_y": undefined, - "widgets_up": undefined, - }, - ], - "_version": 3, - "catch_errors": true, - "config": {}, - "elapsed_time": 0.01, - "errors_in_execution": undefined, - "execution_time": undefined, - "execution_timer_id": undefined, - "extra": {}, - "filter": undefined, - "fixedtime": 0, - "fixedtime_lapse": 0.01, - "globaltime": 0, - "inputs": {}, - "iteration": 0, - "last_update_time": 0, - "links": Map {}, - "list_of_graphcanvas": null, - "nodes_actioning": [], - "nodes_executedAction": [], - "nodes_executing": [], - "outputs": {}, - "runningtime": 0, - "starttime": 0, - "state": { - "lastGroupId": 123, - "lastLinkId": 0, - "lastNodeId": 1, - "lastRerouteId": 0, - }, - "status": 1, - "vars": {}, - "version": 1, -} -`; - -exports[`LGraph > matches previous snapshot > minLGraph 1`] = ` -LGraph { - "_groups": [], - "_input_nodes": undefined, - "_last_trigger_time": undefined, - "_links": Map {}, - "_nodes": [], - "_nodes_by_id": {}, - "_nodes_executable": [], - "_nodes_in_order": [], - "_version": 0, - "catch_errors": true, - "config": {}, - "elapsed_time": 0.01, - "errors_in_execution": undefined, - "execution_time": undefined, - "execution_timer_id": undefined, - "extra": {}, - "filter": undefined, - "fixedtime": 0, - "fixedtime_lapse": 0.01, - "globaltime": 0, - "inputs": {}, - "iteration": 0, - "last_update_time": 0, - "links": Map {}, - "list_of_graphcanvas": null, - "nodes_actioning": [], - "nodes_executedAction": [], - "nodes_executing": [], - "outputs": {}, - "runningtime": 0, - "starttime": 0, - "state": { - "lastGroupId": 0, - "lastLinkId": 0, - "lastNodeId": 0, - "lastRerouteId": 0, - }, - "status": 1, - "vars": {}, - "version": 1, -} -`; - exports[`LGraph > supports schema v0.4 graphs > oldSchemaGraph 1`] = ` LGraph { "_groups": [ diff --git a/test/__snapshots__/LGraph_constructor.test.ts.snap b/test/__snapshots__/LGraph_constructor.test.ts.snap new file mode 100644 index 000000000..432245ebc --- /dev/null +++ b/test/__snapshots__/LGraph_constructor.test.ts.snap @@ -0,0 +1,315 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`LGraph (constructor only) > Matches previous snapshot > basicLGraph 1`] = ` +LGraph { + "_groups": [ + LGraphGroup { + "_bounding": Float32Array [ + 20, + 20, + 1, + 3, + ], + "_children": Set {}, + "_nodes": [], + "_pos": Float32Array [ + 20, + 20, + ], + "_size": Float32Array [ + 1, + 3, + ], + "color": "#6029aa", + "flags": {}, + "font": undefined, + "font_size": 14, + "graph": [Circular], + "id": 123, + "isPointInside": [Function], + "selected": undefined, + "setDirtyCanvas": [Function], + "title": "A group to test with", + }, + ], + "_input_nodes": undefined, + "_last_trigger_time": undefined, + "_links": Map {}, + "_nodes": [ + LGraphNode { + "_collapsed_width": undefined, + "_level": undefined, + "_pos": Float32Array [ + 10, + 10, + ], + "_posSize": Float32Array [ + 10, + 10, + 140, + 60, + ], + "_relative_id": undefined, + "_shape": undefined, + "_size": Float32Array [ + 140, + 60, + ], + "action_call": undefined, + "action_triggered": undefined, + "badgePosition": "top-left", + "badges": [], + "bgcolor": undefined, + "block_delete": undefined, + "boxcolor": undefined, + "clip_area": undefined, + "clonable": undefined, + "color": undefined, + "connections": [], + "console": undefined, + "exec_version": undefined, + "execute_triggered": undefined, + "flags": {}, + "freeWidgetSpace": undefined, + "gotFocusAt": undefined, + "graph": [Circular], + "has_errors": undefined, + "id": 1, + "ignore_remove": undefined, + "inputs": [], + "last_serialization": undefined, + "locked": undefined, + "lostFocusAt": undefined, + "mode": 0, + "mouseOver": undefined, + "optional_inputs": undefined, + "optional_outputs": undefined, + "order": 0, + "outputs": [], + "properties": {}, + "properties_info": [], + "redraw_on_mouse": undefined, + "removable": undefined, + "resizable": undefined, + "selected": undefined, + "serialize_widgets": undefined, + "showAdvanced": undefined, + "title": "LGraphNode", + "type": "mustBeSet", + "widgets": undefined, + "widgets_start_y": undefined, + "widgets_up": undefined, + }, + ], + "_nodes_by_id": { + "1": LGraphNode { + "_collapsed_width": undefined, + "_level": undefined, + "_pos": Float32Array [ + 10, + 10, + ], + "_posSize": Float32Array [ + 10, + 10, + 140, + 60, + ], + "_relative_id": undefined, + "_shape": undefined, + "_size": Float32Array [ + 140, + 60, + ], + "action_call": undefined, + "action_triggered": undefined, + "badgePosition": "top-left", + "badges": [], + "bgcolor": undefined, + "block_delete": undefined, + "boxcolor": undefined, + "clip_area": undefined, + "clonable": undefined, + "color": undefined, + "connections": [], + "console": undefined, + "exec_version": undefined, + "execute_triggered": undefined, + "flags": {}, + "freeWidgetSpace": undefined, + "gotFocusAt": undefined, + "graph": [Circular], + "has_errors": undefined, + "id": 1, + "ignore_remove": undefined, + "inputs": [], + "last_serialization": undefined, + "locked": undefined, + "lostFocusAt": undefined, + "mode": 0, + "mouseOver": undefined, + "optional_inputs": undefined, + "optional_outputs": undefined, + "order": 0, + "outputs": [], + "properties": {}, + "properties_info": [], + "redraw_on_mouse": undefined, + "removable": undefined, + "resizable": undefined, + "selected": undefined, + "serialize_widgets": undefined, + "showAdvanced": undefined, + "title": "LGraphNode", + "type": "mustBeSet", + "widgets": undefined, + "widgets_start_y": undefined, + "widgets_up": undefined, + }, + }, + "_nodes_executable": [], + "_nodes_in_order": [ + LGraphNode { + "_collapsed_width": undefined, + "_level": undefined, + "_pos": Float32Array [ + 10, + 10, + ], + "_posSize": Float32Array [ + 10, + 10, + 140, + 60, + ], + "_relative_id": undefined, + "_shape": undefined, + "_size": Float32Array [ + 140, + 60, + ], + "action_call": undefined, + "action_triggered": undefined, + "badgePosition": "top-left", + "badges": [], + "bgcolor": undefined, + "block_delete": undefined, + "boxcolor": undefined, + "clip_area": undefined, + "clonable": undefined, + "color": undefined, + "connections": [], + "console": undefined, + "exec_version": undefined, + "execute_triggered": undefined, + "flags": {}, + "freeWidgetSpace": undefined, + "gotFocusAt": undefined, + "graph": [Circular], + "has_errors": undefined, + "id": 1, + "ignore_remove": undefined, + "inputs": [], + "last_serialization": undefined, + "locked": undefined, + "lostFocusAt": undefined, + "mode": 0, + "mouseOver": undefined, + "optional_inputs": undefined, + "optional_outputs": undefined, + "order": 0, + "outputs": [], + "properties": {}, + "properties_info": [], + "redraw_on_mouse": undefined, + "removable": undefined, + "resizable": undefined, + "selected": undefined, + "serialize_widgets": undefined, + "showAdvanced": undefined, + "title": "LGraphNode", + "type": "mustBeSet", + "widgets": undefined, + "widgets_start_y": undefined, + "widgets_up": undefined, + }, + ], + "_version": 3, + "catch_errors": true, + "config": {}, + "elapsed_time": 0.01, + "errors_in_execution": undefined, + "execution_time": undefined, + "execution_timer_id": undefined, + "extra": {}, + "filter": undefined, + "fixedtime": 0, + "fixedtime_lapse": 0.01, + "globaltime": 0, + "inputs": {}, + "iteration": 0, + "last_update_time": 0, + "links": Map {}, + "list_of_graphcanvas": null, + "nodes_actioning": [], + "nodes_executedAction": [], + "nodes_executing": [], + "outputs": {}, + "runningtime": 0, + "starttime": 0, + "state": { + "lastGroupId": 123, + "lastLinkId": 0, + "lastNodeId": 1, + "lastRerouteId": 0, + }, + "status": 1, + "vars": {}, + "version": 1, +} +`; + +exports[`LGraph (constructor only) > Matches previous snapshot > minLGraph 1`] = ` +LGraph { + "_groups": [], + "_input_nodes": undefined, + "_last_trigger_time": undefined, + "_links": Map {}, + "_nodes": [], + "_nodes_by_id": {}, + "_nodes_executable": [], + "_nodes_in_order": [], + "_version": 0, + "catch_errors": true, + "config": {}, + "elapsed_time": 0.01, + "errors_in_execution": undefined, + "execution_time": undefined, + "execution_timer_id": undefined, + "extra": {}, + "filter": undefined, + "fixedtime": 0, + "fixedtime_lapse": 0.01, + "globaltime": 0, + "inputs": {}, + "iteration": 0, + "last_update_time": 0, + "links": Map {}, + "list_of_graphcanvas": null, + "nodes_actioning": [], + "nodes_executedAction": [], + "nodes_executing": [], + "outputs": {}, + "runningtime": 0, + "starttime": 0, + "state": { + "lastGroupId": 0, + "lastLinkId": 0, + "lastNodeId": 0, + "lastRerouteId": 0, + }, + "status": 1, + "vars": {}, + "version": 1, +} +`; diff --git a/test/assets/testGraphs.ts b/test/assets/testGraphs.ts index ca2fb5885..d7601aad7 100644 --- a/test/assets/testGraphs.ts +++ b/test/assets/testGraphs.ts @@ -57,6 +57,7 @@ export const basicSerialisableGraph: SerialisableGraph = { nodes: [ { id: 1, + type: "mustBeSet", }, ], links: [], diff --git a/test/serialise.test.ts b/test/serialise.test.ts index 562163b67..e75845c9b 100644 --- a/test/serialise.test.ts +++ b/test/serialise.test.ts @@ -3,7 +3,7 @@ import { LGraph, LGraphGroup, LGraphNode } from "@/litegraph" import { test } from "./testExtensions" import type { ISerialisedGraph } from "@/types/serialisation" -describe.concurrent("LGraph Serialisation", () => { +describe("LGraph Serialisation", () => { test("can (de)serialise node / group titles", ({ expect, minimalGraph }) => { const nodeTitle = "Test Node" const groupTitle = "Test Group" diff --git a/test/testExtensions.ts b/test/testExtensions.ts index 0fb56449d..2cb6f8371 100644 --- a/test/testExtensions.ts +++ b/test/testExtensions.ts @@ -2,14 +2,19 @@ import { test as baseTest } from "vitest" import type { ISerialisedGraph, SerialisableGraph } from "../src/types/serialisation" import { LGraph } from "@/LGraph" import { basicSerialisableGraph, minimalSerialisableGraph, oldSchemaGraph } from "./assets/testGraphs" +import { LiteGraph } from "@/litegraph" interface LitegraphFixtures { minimalGraph: LGraph minimalSerialisableGraph: SerialisableGraph - basicSerialisableGraph: SerialisableGraph oldSchemaGraph: ISerialisedGraph } +/** These fixtures alter global state, and are difficult to reset. Relies on a single test per-file to reset state. */ +interface DirtyFixtures { + basicSerialisableGraph: SerialisableGraph +} + export const test = baseTest.extend({ minimalGraph: async ({ }, use) => { // Before each test function @@ -18,10 +23,21 @@ export const test = baseTest.extend({ // use the fixture value await use(lGraph) - - // After each test function }, - basicSerialisableGraph: structuredClone(basicSerialisableGraph), minimalSerialisableGraph: structuredClone(minimalSerialisableGraph), oldSchemaGraph: structuredClone(oldSchemaGraph), }) + +/** Test that use {@link DirtyFixtures}. One test per file. */ +export const dirtyTest = test.extend({ + basicSerialisableGraph: async ({}, use) => { + if (!basicSerialisableGraph.nodes) throw new Error("Invalid test object") + + // Register node types + for (const node of basicSerialisableGraph.nodes) { + LiteGraph.registerNodeType(node.type!, LiteGraph.LGraphNode) + } + + await use(structuredClone(basicSerialisableGraph)) + }, +}) diff --git a/vite.config.mts b/vite.config.mts index 34399ddf2..f031f5a9d 100644 --- a/vite.config.mts +++ b/vite.config.mts @@ -33,5 +33,7 @@ export default defineConfig({ test: { alias: { "@/": path.resolve(__dirname, "./src/") }, environment: "jsdom", + restoreMocks: true, + unstubGlobals: true, }, })