/
lib-collect-packages.test.js
56 lines (47 loc) · 1.48 KB
/
lib-collect-packages.test.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
"use strict";
// helpers
const buildGraph = require("../__helpers__/build-graph");
// file under test
const collectPackages = require("../lib/collect-packages");
const toNamesList = collection => Array.from(collection).map(pkg => pkg.name);
test("returns all packages", () => {
const graph = buildGraph();
const result = collectPackages(graph);
expect(toNamesList(result)).toMatchInlineSnapshot(`
Array [
"package-cycle-1",
"package-cycle-2",
"package-cycle-extraneous-1",
"package-cycle-extraneous-2",
"package-dag-1",
"package-dag-2a",
"package-dag-2b",
"package-dag-3",
"package-standalone",
]
`);
});
test("filters packages through isCandidate, passing node and name", () => {
const graph = buildGraph();
const packagesToInclude = ["package-cycle-1"];
const isCandidate = (node, name) => {
return packagesToInclude.includes(node.name) && node.name === name;
};
const result = collectPackages(graph, { isCandidate });
expect(toNamesList(result)).toMatchInlineSnapshot(`
Array [
"package-cycle-1",
"package-cycle-2",
"package-cycle-extraneous-1",
"package-cycle-extraneous-2",
]
`);
});
test("calls onInclude with included package name", () => {
const graph = buildGraph();
const packagesToInclude = ["package-standalone"];
const isCandidate = (node, name) => packagesToInclude.includes(name);
const onInclude = jest.fn();
collectPackages(graph, { isCandidate, onInclude });
expect(onInclude).toHaveBeenCalledWith(packagesToInclude[0]);
});