Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add tests for link type
  • Loading branch information
AustinMroz committed Dec 6, 2025
commit 56d8fc233634c12824dfadc3da6cf7d91aa15da0
46 changes: 40 additions & 6 deletions tests-ui/tests/litegraph/core/LGraphNode.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { afterEach, beforeEach, describe, expect, vi } from 'vitest'

import type { INodeInputSlot, Point } from '@/lib/litegraph/src/litegraph'
import { LGraphNode, LiteGraph } from '@/lib/litegraph/src/litegraph'
import { LGraph } from '@/lib/litegraph/src/litegraph'
import { NodeInputSlot } from '@/lib/litegraph/src/litegraph'
import { NodeOutputSlot } from '@/lib/litegraph/src/litegraph'
import type { ISerialisedNode } from '@/lib/litegraph/src/litegraph'
import type {
INodeInputSlot,
Point,
ISerialisedNode
} from '@/lib/litegraph/src/litegraph'
import {
LGraphNode,
LiteGraph,
LGraph,
NodeInputSlot,
NodeOutputSlot
} from '@/lib/litegraph/src/litegraph'

import { test } from './fixtures/testExtensions'

Expand Down Expand Up @@ -261,6 +267,34 @@ describe('LGraphNode', () => {
})
})

describe('Applies correct link type on connection', () => {
it.for<[string, string, string]>([
['IMAGE', 'IMAGE', 'IMAGE'],
['*', 'IMAGE', 'IMAGE'],
['IMAGE', '*', 'IMAGE'],
['*', '*', '*'],
['IMAGE,MASK', 'IMAGE,LATENT', 'IMAGE'],
//An invalid connection should use input type
['Mask', 'IMAGE', 'IMAGE']
])(
'Link from %s to %s should have type %s',
([output, input, expected]) => {
const target = new LGraphNode('target')
const source = new LGraphNode('source')
const graph = new LGraph()

target.addInput(input, input)
source.addOutput(output, output)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Why do we pass input/output twice for each of these?
(I'm intentionally not looking it up)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a filler string for name. Probably should have gone with 'input' and 'output' for clarity.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100% Nit, I'd go with fake_input/fake_output to make it pellucidly clear that this is a completely arbitrary string for test purposes.


graph.add(source)
graph.add(target)

const link = source.connect(0, target, 0)
expect(link?.type).toBe(expected)
}
)
})

describe('getInputPos and getOutputPos', () => {
test('should handle collapsed nodes correctly', () => {
const node = new LGraphNode('TestNode') as unknown as Omit<
Expand Down
Loading