-
Notifications
You must be signed in to change notification settings - Fork 139
/
Copy pathexpand.test.ts
84 lines (72 loc) · 2.37 KB
/
expand.test.ts
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import chalk from "chalk";
import * as DataExpander from "../src/data-expander.js";
import {Utils} from "../src/utils.js";
import assert from "assert";
import {AssertionError} from "assert";
test("VAR w.o. brackets positive", () => {
const expanded = Utils.expandText("$VAR", {VAR: "success"});
expect(expanded).toBe("success");
});
test("VAR w.o. brackets negative", () => {
const expanded = Utils.expandText("$VAR", {UNSET_VAR: "success"});
expect(expanded).toBe("");
});
test("VAR w. brackets postive", () => {
const expanded = Utils.expandText("${VAR}", {VAR: "success"});
expect(expanded).toBe("success");
});
test("VAR w. brackets negative", () => {
const expanded = Utils.expandText("${VAR}", {UNSET_VAR: "success"});
expect(expanded).toBe("");
});
test("VAR w/ escapes", () => {
const expanded = Utils.expandText("$$VAR $$$VAR $$$$VAR", {VAR: "success"});
expect(expanded).toBe("$VAR $success $$VAR");
});
test("Expand null", () => {
const expanded = Utils.expandText(null, {});
expect(expanded).toBe(null);
});
test("extends invalid job", () => {
try {
DataExpander.jobExtends({
"test-job": {extends: ["build-job"]},
});
expect(true).toBe(false);
} catch (e) {
assert(e instanceof AssertionError, "e is not instanceof AssertionError");
expect(e.message).toBe(chalk`{blueBright build-job} is unspecified, used by {blueBright test-job} extends`);
}
});
test("extends infinite loop", () => {
try {
DataExpander.jobExtends({
"build-job": {extends: ["test-job"]},
"test-job": {extends: ["build-job"]},
});
expect(true).toBe(false);
} catch (e) {
assert(e instanceof AssertionError, "e is not instanceof AssertionError");
expect(e.message).toBe(chalk`{blueBright test-job}: circular dependency detected in \`extends\``);
}
});
test("extends simple", () => {
const gitlabData = {
"test-job": {
extends: ["build-job"],
},
"build-job": {
script: ["echo \"Hello, world!\""],
},
};
DataExpander.jobExtends(gitlabData);
const expected = {
"test-job": {
script: ["echo \"Hello, world!\""],
},
"build-job": {
script: ["echo \"Hello, world!\""],
},
};
expect(gitlabData).toEqual(expected);
});