mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-01-26 19:09:52 +00:00
* fix: vite primevue/treenode import error * refactor: remove useless @ts-ignore and replace with @ts-expect-error * build(tsconfig): enable incremental to speed up secondary time type check
41 lines
1.0 KiB
TypeScript
41 lines
1.0 KiB
TypeScript
import { LiteGraph } from '@comfyorg/litegraph'
|
|
import { LGraph } from '@comfyorg/litegraph'
|
|
import { LGraphNode } from '@comfyorg/litegraph'
|
|
|
|
function swapNodes(nodes: LGraphNode[]) {
|
|
const firstNode = nodes[0]
|
|
const lastNode = nodes[nodes.length - 1]
|
|
nodes[0] = lastNode
|
|
nodes[nodes.length - 1] = firstNode
|
|
return nodes
|
|
}
|
|
|
|
function createGraph(...nodes: LGraphNode[]) {
|
|
const graph = new LGraph()
|
|
nodes.forEach((node) => graph.add(node))
|
|
return graph
|
|
}
|
|
|
|
class DummyNode extends LGraphNode {
|
|
constructor() {
|
|
super()
|
|
}
|
|
}
|
|
|
|
describe('LGraph', () => {
|
|
it('should serialize deterministic node order', async () => {
|
|
LiteGraph.registerNodeType('dummy', DummyNode)
|
|
const node1 = new DummyNode()
|
|
const node2 = new DummyNode()
|
|
const graph = createGraph(node1, node2)
|
|
|
|
const result1 = graph.serialize()
|
|
expect(result1.nodes).not.toHaveLength(0)
|
|
// @ts-expect-error
|
|
graph._nodes = swapNodes(graph._nodes)
|
|
const result2 = graph.serialize()
|
|
|
|
expect(result1).toEqual(result2)
|
|
})
|
|
})
|