mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-11 00:10:40 +00:00
[Test] Standardise unit test infrastructure (#572)
* [Test] Revert custom name for test context - Removes "lgTest", replaces with default "test" * nit - Rename test extensions file * Split test graphs out to separate file
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { describe } from "vitest"
|
||||
import { LGraph, LiteGraph } from "@/litegraph"
|
||||
import { lgTest } from "./lgTest"
|
||||
import { test } from "./testExtensions"
|
||||
|
||||
describe.concurrent("LGraph", () => {
|
||||
lgTest("can be instantiated", ({ expect }) => {
|
||||
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)
|
||||
@@ -11,28 +11,28 @@ describe.concurrent("LGraph", () => {
|
||||
expect(graph.extra).toBe("TestGraph")
|
||||
})
|
||||
|
||||
lgTest("populates optional values", ({ expect, minimalSerialisableGraph }) => {
|
||||
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)
|
||||
})
|
||||
|
||||
lgTest("matches previous snapshot", ({ expect, minimalSerialisableGraph, basicSerialisableGraph }) => {
|
||||
test("matches previous snapshot", ({ expect, minimalSerialisableGraph, basicSerialisableGraph }) => {
|
||||
const minLGraph = new LGraph(minimalSerialisableGraph)
|
||||
expect(minLGraph).toMatchSnapshot("minLGraph")
|
||||
const basicLGraph = new LGraph(basicSerialisableGraph)
|
||||
expect(basicLGraph).toMatchSnapshot("basicLGraph")
|
||||
})
|
||||
|
||||
lgTest("supports schema v0.4 graphs", ({ expect, oldSchemaGraph }) => {
|
||||
test("supports schema v0.4 graphs", ({ expect, oldSchemaGraph }) => {
|
||||
const fromOldSchema = new LGraph(oldSchemaGraph)
|
||||
expect(fromOldSchema).toMatchSnapshot("oldSchemaGraph")
|
||||
})
|
||||
})
|
||||
|
||||
describe.concurrent("Legacy LGraph Compatibility Layer", () => {
|
||||
lgTest("can be extended via prototype", ({ expect, minimalGraph }) => {
|
||||
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"
|
||||
@@ -41,7 +41,7 @@ describe.concurrent("Legacy LGraph Compatibility Layer", () => {
|
||||
expect(minimalGraph.newMethod()).toBe("New method added via prototype")
|
||||
})
|
||||
|
||||
lgTest("is correctly assigned to LiteGraph", ({ expect }) => {
|
||||
test("is correctly assigned to LiteGraph", ({ expect }) => {
|
||||
expect(LiteGraph.LGraph).toBe(LGraph)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { describe, expect } from "vitest"
|
||||
import { LGraphGroup } from "@/litegraph"
|
||||
import { lgTest } from "./lgTest"
|
||||
import { test } from "./testExtensions"
|
||||
|
||||
describe("LGraphGroup", () => {
|
||||
lgTest("serializes to the existing format", () => {
|
||||
test("serializes to the existing format", () => {
|
||||
const link = new LGraphGroup("title", 929)
|
||||
expect(link.serialize()).toMatchSnapshot("Basic")
|
||||
})
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { describe, expect } from "vitest"
|
||||
import { LGraphNode } from "@/litegraph"
|
||||
import { NodeInputSlot, NodeOutputSlot } from "@/NodeSlot"
|
||||
import { lgTest } from "./lgTest"
|
||||
import { test } from "./testExtensions"
|
||||
|
||||
describe("LGraphNode", () => {
|
||||
lgTest("should serialize position/size correctly", () => {
|
||||
test("should serialize position/size correctly", () => {
|
||||
const node = new LGraphNode("TestNode")
|
||||
node.pos = [10, 10]
|
||||
expect(node.pos).toEqual(new Float32Array([10, 10]))
|
||||
@@ -15,7 +15,7 @@ describe("LGraphNode", () => {
|
||||
expect(node.serialize().size).toEqual([100, 100])
|
||||
})
|
||||
|
||||
lgTest("should configure inputs correctly", () => {
|
||||
test("should configure inputs correctly", () => {
|
||||
const node = new LGraphNode("TestNode")
|
||||
node.configure({
|
||||
id: 0,
|
||||
@@ -32,7 +32,7 @@ describe("LGraphNode", () => {
|
||||
expect(node.inputs.length).toEqual(1)
|
||||
})
|
||||
|
||||
lgTest("should configure outputs correctly", () => {
|
||||
test("should configure outputs correctly", () => {
|
||||
const node = new LGraphNode("TestNode")
|
||||
node.configure({
|
||||
id: 0,
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { describe, expect } from "vitest"
|
||||
import { LLink } from "@/litegraph"
|
||||
import { lgTest } from "./lgTest"
|
||||
import { test } from "./testExtensions"
|
||||
|
||||
describe("LLink", () => {
|
||||
lgTest("matches previous snapshot", () => {
|
||||
test("matches previous snapshot", () => {
|
||||
const link = new LLink(1, "float", 4, 2, 5, 3)
|
||||
expect(link.serialize()).toMatchSnapshot("Basic")
|
||||
})
|
||||
|
||||
lgTest("serializes to the previous snapshot", () => {
|
||||
test("serializes to the previous snapshot", () => {
|
||||
const link = new LLink(1, "float", 4, 2, 5, 3)
|
||||
expect(link.serialize()).toMatchSnapshot("Basic")
|
||||
})
|
||||
|
||||
63
test/assets/testGraphs.ts
Normal file
63
test/assets/testGraphs.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import type { ISerialisedGraph, SerialisableGraph } from "@/litegraph"
|
||||
|
||||
export const oldSchemaGraph: ISerialisedGraph = {
|
||||
version: 0.4,
|
||||
config: {},
|
||||
last_node_id: 0,
|
||||
last_link_id: 0,
|
||||
groups: [
|
||||
{
|
||||
id: 123,
|
||||
bounding: [20, 20, 1, 3],
|
||||
color: "#6029aa",
|
||||
font_size: 14,
|
||||
title: "A group to test with",
|
||||
},
|
||||
],
|
||||
nodes: [
|
||||
{
|
||||
id: 1,
|
||||
},
|
||||
],
|
||||
links: [],
|
||||
}
|
||||
|
||||
export const minimalSerialisableGraph: SerialisableGraph = {
|
||||
version: 1,
|
||||
config: {},
|
||||
state: {
|
||||
lastNodeId: 0,
|
||||
lastLinkId: 0,
|
||||
lastGroupId: 0,
|
||||
lastRerouteId: 0,
|
||||
},
|
||||
nodes: [],
|
||||
links: [],
|
||||
groups: [],
|
||||
}
|
||||
|
||||
export const basicSerialisableGraph: SerialisableGraph = {
|
||||
version: 1,
|
||||
config: {},
|
||||
state: {
|
||||
lastNodeId: 0,
|
||||
lastLinkId: 0,
|
||||
lastGroupId: 0,
|
||||
lastRerouteId: 0,
|
||||
},
|
||||
groups: [
|
||||
{
|
||||
id: 123,
|
||||
bounding: [20, 20, 1, 3],
|
||||
color: "#6029aa",
|
||||
font_size: 14,
|
||||
title: "A group to test with",
|
||||
},
|
||||
],
|
||||
nodes: [
|
||||
{
|
||||
id: 1,
|
||||
},
|
||||
],
|
||||
links: [],
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
import { test } from "vitest"
|
||||
import type { ISerialisedGraph, SerialisableGraph } from "../src/types/serialisation"
|
||||
import { LGraph } from "@/LGraph"
|
||||
|
||||
const oldSchemaGraph: ISerialisedGraph = {
|
||||
version: 0.4,
|
||||
config: {},
|
||||
last_node_id: 0,
|
||||
last_link_id: 0,
|
||||
groups: [
|
||||
{
|
||||
id: 123,
|
||||
bounding: [20, 20, 1, 3],
|
||||
color: "#6029aa",
|
||||
font_size: 14,
|
||||
title: "A group to test with",
|
||||
},
|
||||
],
|
||||
nodes: [
|
||||
{
|
||||
id: 1,
|
||||
},
|
||||
],
|
||||
links: [],
|
||||
}
|
||||
|
||||
const minimalSerialisableGraph: SerialisableGraph = {
|
||||
version: 1,
|
||||
config: {},
|
||||
state: {
|
||||
lastNodeId: 0,
|
||||
lastLinkId: 0,
|
||||
lastGroupId: 0,
|
||||
lastRerouteId: 0
|
||||
},
|
||||
nodes: [],
|
||||
links: [],
|
||||
groups: [],
|
||||
}
|
||||
|
||||
const basicSerialisableGraph: SerialisableGraph = {
|
||||
version: 1,
|
||||
config: {},
|
||||
state: {
|
||||
lastNodeId: 0,
|
||||
lastLinkId: 0,
|
||||
lastGroupId: 0,
|
||||
lastRerouteId: 0
|
||||
},
|
||||
groups: [
|
||||
{
|
||||
id: 123,
|
||||
bounding: [20, 20, 1, 3],
|
||||
color: "#6029aa",
|
||||
font_size: 14,
|
||||
title: "A group to test with",
|
||||
},
|
||||
],
|
||||
nodes: [
|
||||
{
|
||||
id: 1,
|
||||
},
|
||||
],
|
||||
links: [],
|
||||
}
|
||||
|
||||
interface LitegraphFixtures {
|
||||
minimalGraph: LGraph
|
||||
minimalSerialisableGraph: SerialisableGraph
|
||||
basicSerialisableGraph: SerialisableGraph
|
||||
oldSchemaGraph: ISerialisedGraph
|
||||
}
|
||||
|
||||
export const lgTest = test.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)
|
||||
|
||||
// After each test function
|
||||
},
|
||||
basicSerialisableGraph: structuredClone(basicSerialisableGraph),
|
||||
minimalSerialisableGraph: structuredClone(minimalSerialisableGraph),
|
||||
oldSchemaGraph: structuredClone(oldSchemaGraph),
|
||||
})
|
||||
@@ -1,20 +1,20 @@
|
||||
import { describe, expect } from "vitest"
|
||||
import { clamp, LGraphCanvas, LiteGraph } from "@/litegraph"
|
||||
import { LiteGraphGlobal } from "@/LiteGraphGlobal"
|
||||
import { lgTest } from "./lgTest"
|
||||
import { test } from "./testExtensions"
|
||||
|
||||
describe.concurrent("Litegraph module", () => {
|
||||
lgTest("contains a global export", ({ expect }) => {
|
||||
test("contains a global export", ({ expect }) => {
|
||||
expect(LiteGraph).toBeInstanceOf(LiteGraphGlobal)
|
||||
expect(LiteGraph.LGraphCanvas).toBe(LGraphCanvas)
|
||||
})
|
||||
|
||||
lgTest("has the same structure", ({ expect }) => {
|
||||
test("has the same structure", ({ expect }) => {
|
||||
const lgGlobal = new LiteGraphGlobal()
|
||||
expect(lgGlobal).toMatchSnapshot("minLGraph")
|
||||
})
|
||||
|
||||
lgTest("clamps values", () => {
|
||||
test("clamps values", () => {
|
||||
expect(clamp(-1.124, 13, 24)).toStrictEqual(13)
|
||||
expect(clamp(Infinity, 18, 29)).toStrictEqual(29)
|
||||
})
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { describe } from "vitest"
|
||||
import { LGraph, LGraphGroup, LGraphNode } from "@/litegraph"
|
||||
import { lgTest } from "./lgTest"
|
||||
import { test } from "./testExtensions"
|
||||
import type { ISerialisedGraph } from "@/types/serialisation"
|
||||
|
||||
describe.concurrent("LGraph Serialisation", () => {
|
||||
lgTest("can (de)serialise node / group titles", ({ expect, minimalGraph }) => {
|
||||
test("can (de)serialise node / group titles", ({ expect, minimalGraph }) => {
|
||||
const nodeTitle = "Test Node"
|
||||
const groupTitle = "Test Group"
|
||||
|
||||
|
||||
27
test/testExtensions.ts
Normal file
27
test/testExtensions.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { test as baseTest } from "vitest"
|
||||
import type { ISerialisedGraph, SerialisableGraph } from "../src/types/serialisation"
|
||||
import { LGraph } from "@/LGraph"
|
||||
import { basicSerialisableGraph, minimalSerialisableGraph, oldSchemaGraph } from "./assets/testGraphs"
|
||||
|
||||
interface LitegraphFixtures {
|
||||
minimalGraph: LGraph
|
||||
minimalSerialisableGraph: SerialisableGraph
|
||||
basicSerialisableGraph: SerialisableGraph
|
||||
oldSchemaGraph: ISerialisedGraph
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
// After each test function
|
||||
},
|
||||
basicSerialisableGraph: structuredClone(basicSerialisableGraph),
|
||||
minimalSerialisableGraph: structuredClone(minimalSerialisableGraph),
|
||||
oldSchemaGraph: structuredClone(oldSchemaGraph),
|
||||
})
|
||||
Reference in New Issue
Block a user