-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath-sort.test.js
43 lines (39 loc) · 1.07 KB
/
path-sort.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
const pathSort = require("./path-sort");
function testSet(omissions, inclusions) {
return []
.concat(
omissions.map(key => ({ key, action: "omit" })),
inclusions.map(key => ({ key, action: "include" }))
)
.sort(pathSort);
}
function compareSet(actual, expected) {
const errors = [];
for (let i = 0; i < actual.length; i++) {
try {
console.assert(
actual[i].key === expected[i].key,
"Incorrect key:\n" +
`Expected: ${expected[i].key}.\nActual: ${actual[i].key}`
);
console.assert(
actual[i].action === expected[i].action,
"Incorrect action:\n" +
`Expected: ${expected[i].action}.\nActual: ${actual[i].action}`
);
} catch (e) {
errors.push(e);
}
}
if (errors.length > 0) {
errors.map(console.error);
process.exit(1);
}
}
const O = "omit";
const I = "include";
compareSet(testSet(["repository", "dependencies"], ["dependencies.color"]), [
{ key: "dependencies", action: O },
{ key: "dependencies.color", action: I },
{ key: "repository", action: O }
]);