Skip to content

Commit 82887f5

Browse files
committed
test(core): refactor version cases
1 parent 3804176 commit 82887f5

File tree

1 file changed

+37
-32
lines changed

1 file changed

+37
-32
lines changed

@commitlint/core/src/library/is-ignored.test.js

+37-32
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,36 @@
11
import test from 'ava';
22
import isIgnored from './is-ignored';
33

4+
const VERSION_MESSAGES = [
5+
'0.0.1',
6+
'0.1.0',
7+
'1.0.0',
8+
'0.0.1-alpha',
9+
'0.0.1-some-crazy-tag',
10+
'0.0.1-0',
11+
'0.0.1-999',
12+
'0.0.1-alpha.0',
13+
'0.0.1-alpha.999',
14+
'0.0.1-some-crazy-tag.0',
15+
'0.0.1-some-crazy-tag.999',
16+
'0.0.1-1e69d54',
17+
'v0.0.1',
18+
' v3.0.0'
19+
];
20+
21+
const AMENDMENTS = [
22+
'Signed-off-by: Developer <[email protected]>',
23+
'Change-Id: I895114872a515a269487a683124b63303818e19c',
24+
'Signed-off-by: Developer <[email protected]>\nChange-Id: I895114872a515a269487a683124b63303818e19c'
25+
];
26+
27+
const AMENDED_VERSION_MESSAGES = VERSION_MESSAGES.reduce((results, message) => {
28+
return [
29+
...results,
30+
...AMENDMENTS.map(amendment => `${message}\n\n${amendment}`)
31+
];
32+
}, []);
33+
434
test('should return false when called without arguments', t => {
535
t.false(isIgnored());
636
});
@@ -13,7 +43,7 @@ test('should return false for normal commit', t => {
1343
t.false(isIgnored('initial commit'));
1444
});
1545

16-
test('should return false for branch merges', t => {
46+
test('should return true for branch merges', t => {
1747
t.true(isIgnored("Merge branch 'iss53'"));
1848
});
1949

@@ -34,38 +64,13 @@ test('should return true for revert commits', t => {
3464
);
3565
});
3666

37-
const versionCommitInputs = [
38-
'0.0.1',
39-
'0.1.0',
40-
'1.0.0',
41-
'0.0.1-alpha',
42-
'0.0.1-some-crazy-tag',
43-
'0.0.1-0',
44-
'0.0.1-999',
45-
'0.0.1-alpha.0',
46-
'0.0.1-alpha.999',
47-
'0.0.1-some-crazy-tag.0',
48-
'0.0.1-some-crazy-tag.999',
49-
'0.0.1-1e69d54',
50-
'v0.0.1',
51-
' v3.0.0'
52-
];
53-
for (let i = 0, len = versionCommitInputs.length; i < len; i++) {
54-
const input = versionCommitInputs[i];
55-
const commitMsg1 = input;
56-
const commitMsg2 = `${input}\n\nSigned-off-by: Developer <[email protected]>`;
57-
const commitMsg3 = `${input}\n\nChange-Id: I895114872a515a269487a683124b63303818e19c`;
58-
const commitMsg4 = `${input}\n\nSigned-off-by: Developer <[email protected]>\nChange-Id: I895114872a515a269487a683124b63303818e19c`;
59-
60-
console.log(commitMsg1, commitMsg2, commitMsg3, commitMsg4);
67+
test('should ignore npm semver commits', t => {
68+
VERSION_MESSAGES.forEach(message => t.true(isIgnored(message)));
69+
});
6170

62-
test(`should return true for version commit permutations of '${input}'`, t => {
63-
t.true(isIgnored(commitMsg1));
64-
t.true(isIgnored(commitMsg2));
65-
t.true(isIgnored(commitMsg3));
66-
t.true(isIgnored(commitMsg4));
67-
});
68-
}
71+
test('should ignore npm semver commits with footers', t => {
72+
AMENDED_VERSION_MESSAGES.forEach(message => t.true(isIgnored(message)));
73+
});
6974

7075
test('should return true fixup commits', t => {
7176
t.true(isIgnored('fixup! initial commit'));

0 commit comments

Comments
 (0)