-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.js
More file actions
200 lines (162 loc) · 5.87 KB
/
index.test.js
File metadata and controls
200 lines (162 loc) · 5.87 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
const lint = require("@commitlint/lint");
const functionRules = require("commitlint-plugin-function-rules");
const { rules, parserOpts } = require(".");
const lintMessage = async message =>
lint.default(message.replace(/^\s+/, "").trim(), rules, {
parserOpts,
plugins: {
"commitlint-plugin-function-rules": functionRules
}
});
test("a valid commit message", async () => {
const { valid, errors, warnings } = await lintMessage(
"feat(RCD-1): a valid commit message"
);
expect(valid).toBe(true);
expect(errors).toStrictEqual([]);
expect(warnings).toStrictEqual([]);
});
test("a valid multi line commit", async () => {
const { valid, errors, warnings } = await lintMessage(
`test(RCD-1): a valid angular commit with a scope
Some content in the body`
);
expect(valid).toBe(true);
expect(errors).toStrictEqual([]);
expect(warnings).toStrictEqual([]);
});
test("a leading blank line after header", async () => {
const { valid, errors, warnings } = await lintMessage(
`test(RCD-1): a valid angular commit with a scope
Some content in the body`
);
expect(valid).toBe(false);
expect(errors[0].message).toBe("body must have leading blank line");
expect(warnings).toStrictEqual([]);
});
test("an invalid scope", async () => {
const { valid, errors, warnings } = await lintMessage(
`no: no is not not an invalid commit type`
);
expect(valid).toBe(false);
expect(errors[0].message).toBe(
"type must be one of [build, ci, docs, feat, fix, perf, refactor, revert, style, test]"
);
expect(warnings).toStrictEqual([]);
});
test("no type", async () => {
const { valid, errors, warnings } = await lintMessage(
`feat: no is not not an invalid commit type`
);
expect(valid).toBe(false);
expect(errors[0].message).toBe("a scope must be set");
expect(warnings).toStrictEqual([]);
});
test("an invalid type", async () => {
const { valid, errors, warnings } = await lintMessage(
`feat(heya): no is not not an invalid commit type`
);
expect(valid).toBe(false);
expect(errors[0].message).toBe("scope must be upper-case");
expect(warnings).toStrictEqual([]);
});
test("an invalid jira id", async () => {
const { valid, errors, warnings } = await lintMessage(
`feat(HEYA): no is not not an invalid commit type`
);
expect(valid).toBe(false);
expect(errors[0].message).toBe("scope must be a JIRA issue ID");
expect(warnings).toStrictEqual([]);
});
test("a long header", async () => {
const { valid, errors, warnings } = await lintMessage(
`test(RCD-1): that its an error when there is ia realllllllllllllllllllllly long header`
);
expect(valid).toBe(false);
expect(errors[0].message).toBe(
"header must not be longer than 72 characters, current length is 86"
);
expect(warnings).toStrictEqual([]);
});
test("message header with ! in it", async () => {
const { valid, errors, warnings } = await lintMessage(
`test!: with a breaking change in the type`
);
expect(valid).toBe(false);
expect(errors[0].message).toBe("a scope must be set");
expect(warnings).toStrictEqual([]);
});
test("message header with ! in it and a scope", async () => {
const { valid, errors, warnings } = await lintMessage(
`test(RCD-1)!: with a breaking change in the type`
);
expect(valid).toBe(true);
expect(errors).toStrictEqual([]);
expect(warnings).toStrictEqual([]);
});
test("a subject must be set", async () => {
const { valid, errors, warnings } = await lintMessage(`test(RCD-1):`);
expect(valid).toBe(false);
expect(errors[0].message).toBe("a subject must be set");
expect(warnings).toStrictEqual([]);
});
test("a colon must be set", async () => {
const { valid, errors, warnings } = await lintMessage(
`test(RCD-1) dwadwadwa`
);
expect(valid).toBe(false);
expect(errors[0].message).toBe("a subject must be set");
expect(warnings).toStrictEqual([]);
});
test("JIRA ID key must be upper case", async () => {
const { valid, errors, warnings } = await lintMessage(
`test(rcd-1): a valid commit message`
);
expect(valid).toBe(false);
expect(errors[0].message).toBe("scope must be upper-case");
expect(warnings).toStrictEqual([]);
});
test("you should be able to revert commits", async () => {
const { valid, errors, warnings } = await lintMessage(
`revert(RCD-2): feat(RCD-1): a valid commit message`
);
expect(valid).toBe(true);
expect(errors).toStrictEqual([]);
expect(warnings).toStrictEqual([]);
});
test("revert commits should have the full commit name that is being reverted", async () => {
const { valid, errors, warnings } = await lintMessage(
`revert(RCD-1): a valid commit message`
);
expect(valid).toBe(false);
expect(errors[0].message).toBe(
"revert commits should have the full commit name that is being reverted"
);
expect(warnings).toStrictEqual([]);
});
test("revert commits should have the associated JIRA ID", async () => {
const { valid, errors, warnings } = await lintMessage(
`revert: test(RCD-1): a valid commit message`
);
expect(valid).toBe(false);
expect(errors[0].message).toBe(
"revert commits should have the associated JIRA ID includes in the revert scope"
);
expect(warnings).toStrictEqual([]);
});
test("you should be able to revert commits and make breaking changes in them", async () => {
const { valid, errors, warnings } = await lintMessage(
`revert(RCD-2)!: feat(RCD-1): a valid commit message`
);
expect(valid).toBe(true);
expect(errors).toStrictEqual([]);
expect(warnings).toStrictEqual([]);
});
test("you should be able to revert commits that have breaking changes and make breaking changes in them", async () => {
const { valid, errors, warnings } = await lintMessage(
`revert(RCD-2)!: feat(RCD-1)!: a valid commit message`
);
expect(valid).toBe(true);
expect(errors).toStrictEqual([]);
expect(warnings).toStrictEqual([]);
});