ES6 class convertion of LGraph (#63)

* LGraph ES6 class conversion

* Add compatibility to prototype extension

* Add jest test action

---------

Co-authored-by: filtered <176114999+webfiltered@users.noreply.github.com>
This commit is contained in:
Chenlei Hu
2024-08-09 11:20:05 -04:00
committed by GitHub
parent 9b229220a3
commit 16a3d384b6
8 changed files with 6320 additions and 1667 deletions

39
test/LGraph.test.ts Normal file
View File

@@ -0,0 +1,39 @@
import {
LGraphES6 as LGraph,
LGraph as LegacyLGraph,
LiteGraph,
} from "../dist/litegraph.es.js";
describe("LegacyLGraph Compatibility Layer", () => {
test("LegacyLGraph can be instantiated", () => {
const graph = new LegacyLGraph({extra: "TestGraph"});
expect(graph).toBeInstanceOf(LGraph);
expect(graph).toBeInstanceOf(LegacyLGraph);
expect(graph.extra).toBe("TestGraph");
});
test("LegacyLGraph can be extended via prototype", () => {
LegacyLGraph.prototype.newMethod = function () {
return "New method added via prototype";
};
const graph = new LegacyLGraph();
expect(graph.newMethod()).toBe("New method added via prototype");
});
test("Extensions to LegacyLGraph affect LGraph instances", () => {
LegacyLGraph.prototype.anotherMethod = function () {
return "Another method";
};
const legacyGraph = new LegacyLGraph();
const normalGraph = new LGraph();
expect(legacyGraph.anotherMethod()).toBe("Another method");
expect(normalGraph.anotherMethod()).toBe("Another method");
});
test("LegacyLGraph is correctly assigned to LiteGraph", () => {
expect(LiteGraph.LGraph).toBe(LegacyLGraph);
});
});