mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-02 20:22:08 +00:00
Add 'src/lib/litegraph/' from commit '1b58bf4966e9cdaa04bfaa40f5650b6c6680ab97'
git-subtree-dir: src/lib/litegraph git-subtree-mainline:1eadf80fecgit-subtree-split:1b58bf4966
This commit is contained in:
66
src/lib/litegraph/test/testExtensions.ts
Normal file
66
src/lib/litegraph/test/testExtensions.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import type { ISerialisedGraph, SerialisableGraph } from "../src/types/serialisation"
|
||||
|
||||
import { test as baseTest } from "vitest"
|
||||
|
||||
import { LGraph } from "@/LGraph"
|
||||
import { LiteGraph } from "@/litegraph"
|
||||
|
||||
import floatingBranch from "./assets/floatingBranch.json"
|
||||
import floatingLink from "./assets/floatingLink.json"
|
||||
import linkedNodes from "./assets/linkedNodes.json"
|
||||
import reroutesComplex from "./assets/reroutesComplex.json"
|
||||
import { basicSerialisableGraph, minimalSerialisableGraph, oldSchemaGraph } from "./assets/testGraphs"
|
||||
|
||||
interface LitegraphFixtures {
|
||||
minimalGraph: LGraph
|
||||
minimalSerialisableGraph: SerialisableGraph
|
||||
oldSchemaGraph: ISerialisedGraph
|
||||
floatingLinkGraph: ISerialisedGraph
|
||||
linkedNodesGraph: ISerialisedGraph
|
||||
floatingBranchGraph: LGraph
|
||||
reroutesComplexGraph: LGraph
|
||||
}
|
||||
|
||||
/** 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<LitegraphFixtures>({
|
||||
minimalGraph: async ({ }, use) => {
|
||||
// Before each test function
|
||||
const serialisable = structuredClone(minimalSerialisableGraph)
|
||||
const lGraph = new LGraph(serialisable)
|
||||
|
||||
// use the fixture value
|
||||
await use(lGraph)
|
||||
},
|
||||
minimalSerialisableGraph: structuredClone(minimalSerialisableGraph),
|
||||
oldSchemaGraph: structuredClone(oldSchemaGraph),
|
||||
floatingLinkGraph: structuredClone(floatingLink as unknown as ISerialisedGraph),
|
||||
linkedNodesGraph: structuredClone(linkedNodes as unknown as ISerialisedGraph),
|
||||
floatingBranchGraph: async ({}, use) => {
|
||||
const cloned = structuredClone(floatingBranch as unknown as ISerialisedGraph)
|
||||
const graph = new LGraph(cloned)
|
||||
await use(graph)
|
||||
},
|
||||
reroutesComplexGraph: async ({}, use) => {
|
||||
const cloned = structuredClone(reroutesComplex as unknown as ISerialisedGraph)
|
||||
const graph = new LGraph(cloned)
|
||||
await use(graph)
|
||||
},
|
||||
})
|
||||
|
||||
/** Test that use {@link DirtyFixtures}. One test per file. */
|
||||
export const dirtyTest = test.extend<DirtyFixtures>({
|
||||
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))
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user