Files
ComfyUI_frontend/test/LGraph.test.ts
filtered 6224d2dc06 [Cleanup] Update ESLint rules with stricter auto-fixes (#614)
Stylistic plugin falls short in a few areas when it comes to consistent
lists and chaining. Replaced some key rules with antfu's personal
variants.

`eslint` can now be run repo-wide without params.
2025-02-26 11:12:03 +00:00

51 lines
1.7 KiB
TypeScript

import { describe } from "vitest"
import { LGraph, LiteGraph } from "@/litegraph"
import { test } from "./testExtensions"
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" })
expect(graph).toBeInstanceOf(LGraph)
expect(graph.extra).toBe("TestGraph")
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)
expect(dGraph.nodes).toBeInstanceOf(Array)
expect(dGraph.groups).toBeInstanceOf(Array)
})
test("supports schema v0.4 graphs", ({ expect, oldSchemaGraph }) => {
const fromOldSchema = new LGraph(oldSchemaGraph)
expect(fromOldSchema).toMatchSnapshot("oldSchemaGraph")
})
})
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 () {
return "New method added via prototype"
}
// @ts-expect-error Should always be an error.
expect(minimalGraph.newMethod()).toBe("New method added via prototype")
})
test("is correctly assigned to LiteGraph", ({ expect }) => {
expect(LiteGraph.LGraph).toBe(LGraph)
})
})