-
-
Notifications
You must be signed in to change notification settings - Fork 518
/
Copy pathDependencyGraphTest.js
62 lines (48 loc) · 1.76 KB
/
DependencyGraphTest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import test from "ava";
import { DepGraph as DependencyGraph } from "dependency-graph";
test("Dependency graph nodes don’t require dependencies", async (t) => {
let graph = new DependencyGraph();
graph.addNode("all");
graph.addNode("template-a");
graph.addNode("template-b");
graph.addNode("template-c");
let order = graph.overallOrder();
t.true(order.includes("all"));
t.true(order.includes("template-a"));
t.true(order.includes("template-b"));
t.true(order.includes("template-c"));
// in order of addNode
t.deepEqual(graph.overallOrder(), ["all", "template-a", "template-b", "template-c"]);
});
test("Dependency graph relationships", async (t) => {
let graph = new DependencyGraph();
graph.addNode("all");
graph.addNode("template-a");
graph.addNode("template-b");
graph.addNode("template-c");
graph.addNode("userCollection");
graph.addDependency("all", "template-a");
graph.addDependency("all", "template-b");
graph.addDependency("all", "template-c");
graph.addDependency("userCollection", "all");
t.deepEqual(graph.overallOrder(), [
"template-a",
"template-b",
"template-c",
"all",
"userCollection",
]);
});
test("Do dependencies get removed when nodes are deleted?", async (t) => {
let graph = new DependencyGraph();
graph.addNode("template-a");
graph.addNode("template-b");
graph.addDependency("template-a", "template-b");
t.deepEqual(graph.overallOrder(), ["template-b", "template-a"]);
t.deepEqual(graph.dependenciesOf("template-a"), ["template-b"]);
graph.removeNode("template-b");
t.deepEqual(graph.dependenciesOf("template-a"), []);
graph.addNode("template-b");
t.deepEqual(graph.dependenciesOf("template-a"), []);
t.deepEqual(graph.overallOrder(), ["template-a", "template-b"]);
});