mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-03 12:42:01 +00:00
chore: migrate tests from tests-ui/ to colocate with source files (#7811)
## Summary Migrates all unit tests from `tests-ui/` to colocate with their source files in `src/`, improving discoverability and maintainability. ## Changes - **What**: Relocated all unit tests to be adjacent to the code they test, following the `<source>.test.ts` naming convention - **Config**: Updated `vitest.config.ts` to remove `tests-ui` include pattern and `@tests-ui` alias - **Docs**: Moved testing documentation to `docs/testing/` with updated paths and patterns ## Review Focus - Migration patterns documented in `temp/plans/migrate-tests-ui-to-src.md` - Tests use `@/` path aliases instead of relative imports - Shared fixtures placed in `__fixtures__/` directories ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-7811-chore-migrate-tests-from-tests-ui-to-colocate-with-source-files-2da6d73d36508147a4cce85365dee614) by [Unito](https://www.unito.io) --------- Co-authored-by: Amp <amp@ampcode.com> Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import type {
|
||||
LGraph,
|
||||
LGraphNode,
|
||||
Subgraph
|
||||
} from '@/lib/litegraph/src/litegraph'
|
||||
import {
|
||||
collectMissingNodes,
|
||||
graphHasMissingNodes
|
||||
} from '@/workbench/extensions/manager/utils/graphHasMissingNodes'
|
||||
import type { NodeDefLookup } from '@/workbench/extensions/manager/utils/graphHasMissingNodes'
|
||||
import type { ComfyNodeDefImpl } from '@/stores/nodeDefStore'
|
||||
|
||||
type NodeDefs = NodeDefLookup
|
||||
|
||||
let nodeIdCounter = 0
|
||||
const mockNodeDef = {} as ComfyNodeDefImpl
|
||||
|
||||
const createGraph = (nodes: LGraphNode[] = []): LGraph => {
|
||||
return { nodes } as Partial<LGraph> as LGraph
|
||||
}
|
||||
|
||||
const createSubgraph = (nodes: LGraphNode[]): Subgraph => {
|
||||
return { nodes } as Partial<Subgraph> as Subgraph
|
||||
}
|
||||
|
||||
const createNode = (
|
||||
type?: string,
|
||||
subgraphNodes?: LGraphNode[]
|
||||
): LGraphNode => {
|
||||
return {
|
||||
id: nodeIdCounter++,
|
||||
type,
|
||||
isSubgraphNode: subgraphNodes ? () => true : undefined,
|
||||
subgraph: subgraphNodes ? createSubgraph(subgraphNodes) : undefined
|
||||
} as unknown as LGraphNode
|
||||
}
|
||||
|
||||
describe('graphHasMissingNodes', () => {
|
||||
it('returns false when graph is null', () => {
|
||||
expect(graphHasMissingNodes(null, {})).toBe(false)
|
||||
})
|
||||
|
||||
it('returns false when graph is undefined', () => {
|
||||
expect(graphHasMissingNodes(undefined, {})).toBe(false)
|
||||
})
|
||||
|
||||
it('returns false when graph has no nodes', () => {
|
||||
expect(graphHasMissingNodes(createGraph(), {})).toBe(false)
|
||||
})
|
||||
|
||||
it('returns false when every node has a definition', () => {
|
||||
const graph = createGraph([createNode('FooNode'), createNode('BarNode')])
|
||||
const nodeDefs: NodeDefs = {
|
||||
FooNode: mockNodeDef,
|
||||
BarNode: mockNodeDef
|
||||
}
|
||||
|
||||
expect(graphHasMissingNodes(graph, nodeDefs)).toBe(false)
|
||||
})
|
||||
|
||||
it('returns true when at least one node is missing', () => {
|
||||
const graph = createGraph([
|
||||
createNode('FooNode'),
|
||||
createNode('MissingNode')
|
||||
])
|
||||
const nodeDefs: NodeDefs = {
|
||||
FooNode: mockNodeDef
|
||||
}
|
||||
|
||||
expect(graphHasMissingNodes(graph, nodeDefs)).toBe(true)
|
||||
})
|
||||
|
||||
it('checks nodes nested in subgraphs', () => {
|
||||
const graph = createGraph([
|
||||
createNode('ContainerNode', [createNode('InnerMissing')])
|
||||
])
|
||||
const nodeDefs: NodeDefs = {
|
||||
ContainerNode: mockNodeDef
|
||||
}
|
||||
|
||||
const missingNodes = collectMissingNodes(graph, nodeDefs)
|
||||
expect(missingNodes).toHaveLength(1)
|
||||
expect(missingNodes[0]?.type).toBe('InnerMissing')
|
||||
})
|
||||
|
||||
it('ignores nodes without a type', () => {
|
||||
const graph = createGraph([
|
||||
createNode(undefined),
|
||||
createNode(null as unknown as string)
|
||||
])
|
||||
|
||||
expect(graphHasMissingNodes(graph, {})).toBe(false)
|
||||
})
|
||||
|
||||
it('traverses deeply nested subgraphs', () => {
|
||||
const deepGraph = createGraph([
|
||||
createNode('Layer1', [
|
||||
createNode('Layer2', [
|
||||
createNode('Layer3', [createNode('MissingDeep')])
|
||||
])
|
||||
])
|
||||
])
|
||||
const nodeDefs: NodeDefs = {
|
||||
Layer1: mockNodeDef,
|
||||
Layer2: mockNodeDef,
|
||||
Layer3: mockNodeDef
|
||||
}
|
||||
|
||||
const missingNodes = collectMissingNodes(deepGraph, nodeDefs)
|
||||
expect(missingNodes).toHaveLength(1)
|
||||
expect(missingNodes[0]?.type).toBe('MissingDeep')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user