-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.test.js
73 lines (65 loc) · 2.28 KB
/
index.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const index = require("./index");
describe("index module", () => {
it("rejects if the template cannot be found", () => {
const OPTIONS = {};
const RANGE = "since..to";
return expect(index(OPTIONS, RANGE, "missing-template")).rejects.toThrow(/template file/);
});
it("rejects if the configuration in invalid", () => {
const OPTIONS = { f: "missing-configuration" };
const RANGE = "since..to";
return expect(index(OPTIONS, RANGE, "markdown")).rejects.toThrow(/configuration file/);
});
it("rejects if git log range is invalid", () => {
const OPTIONS = {};
const RANGE = "since..to";
return expect(index(OPTIONS, RANGE, "markdown")).rejects.toThrow(/git log exited/i);
});
it("rejects if the external script fails", () => {
const OPTIONS = {
script: "lib/__tests__/scripts/throws.js",
branch: "testing-branch",
};
const RANGE = "7d27899..28b863e";
return expect(index(OPTIONS, RANGE, "markdown")).rejects.toThrow(/processing external script/i);
});
it("rejects if the rendering template causes errors", () => {
const OPTIONS = {
script: "lib/__tests__/scripts/rename.js",
branch: "testing-branch",
};
const RANGE = "7d27899..28b863e";
return expect(index(OPTIONS, RANGE, "lib/__tests__/templates/invalid.ejs")).rejects.toThrow(
/broken is not defined/i
);
});
it("resolves with the rendered template", () => {
const OPTIONS = {
branch: "testing-branch",
};
const RANGE = "7d27899..28b863e";
return expect(index(OPTIONS, RANGE, "markdown")).resolves.toMatch(/__2.1.0__/i);
});
it("resolves with the postprocessing function", () => {
const OPTIONS = {
script: (data, callback) => {
callback({
foo: "bar",
});
},
branch: "testing-branch",
};
const RANGE = "7d27899..28b863e";
return expect(index(OPTIONS, RANGE, "lib/__tests__/templates/custom.ejs")).resolves.toMatch(/bar/i);
});
it("resolves with the throw postprocessing function", () => {
const OPTIONS = {
script: () => {
throw Error("from script");
},
branch: "testing-branch",
};
const RANGE = "7d27899..28b863e";
return expect(index(OPTIONS, RANGE, "markdown")).rejects.toThrow(/processing external function/i);
});
});