forked from conventional-changelog/commitlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
153 lines (129 loc) Β· 4.15 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
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
import test from 'ava';
import isIgnored from '.';
const VERSION_MESSAGES = [
'0.0.1',
'0.1.0',
'1.0.0',
'0.0.1-alpha',
'0.0.1-some-crazy-tag',
'0.0.1-0',
'0.0.1-999',
'0.0.1-alpha.0',
'0.0.1-alpha.999',
'0.0.1-some-crazy-tag.0',
'0.0.1-some-crazy-tag.999',
'0.0.1-1e69d54',
'v0.0.1',
' v3.0.0'
];
const AMENDMENTS = [
'Signed-off-by: Developer <[email protected]>',
'Change-Id: I895114872a515a269487a683124b63303818e19c',
'Signed-off-by: Developer <[email protected]>\nChange-Id: I895114872a515a269487a683124b63303818e19c'
];
const AMENDED_VERSION_MESSAGES = VERSION_MESSAGES.reduce((results, message) => {
return [
...results,
...AMENDMENTS.map(amendment => `${message}\n\n${amendment}`)
];
}, []);
test('should return false when called without arguments', t => {
t.false(isIgnored());
});
test('should return false when called with empty string', t => {
t.false(isIgnored(''));
});
test('should return false for normal commit', t => {
t.false(isIgnored('initial commit'));
});
test('should return true for branch merges', t => {
t.true(isIgnored("Merge branch 'iss53'"));
});
test('should return true for branch merges with newline characters', t => {
t.true(isIgnored("Merge branch 'ctrom-YarnBuild'\n"));
t.true(isIgnored("Merge branch 'ctrom-YarnBuild'\r\n"));
});
test('should return true for branch merges with multiple newline characters', t => {
t.true(isIgnored("Merge branch 'ctrom-YarnBuild'\n\n\n"));
t.true(isIgnored("Merge branch 'ctrom-YarnBuild'\r\n\r\n\r\n"));
});
test('should return true for merged PRs', t => {
t.true(isIgnored('Merge pull request #369'));
});
test('should return true for branch merges with newline characters and more characters after it', t => {
t.true(isIgnored("Merge branch 'ctrom-YarnBuild'\n "));
t.true(isIgnored("Merge branch 'ctrom-YarnBuild'\r\n # some comment"));
});
test('should return true for revert commits', t => {
t.true(
isIgnored(
`Revert "docs: add recipe for linting of all commits in a PR (#36)"\n\nThis reverts commit 1e69d542c16c2a32acfd139e32efa07a45f19111.`
)
);
t.true(
isIgnored(
`revert "docs: add recipe for linting of all commits in a PR (#36)"\n\nThis reverts commit 1e69d542c16c2a32acfd139e32efa07a45f19111.`
)
);
});
test('should ignore npm semver commits', t => {
VERSION_MESSAGES.forEach(message => t.true(isIgnored(message)));
});
test('should ignore npm semver commits with chore', t => {
VERSION_MESSAGES.forEach(message => t.true(isIgnored(`chore: ${message}`)));
VERSION_MESSAGES.forEach(message =>
t.true(isIgnored(`chore(release): ${message}`))
);
});
test('should ignore npm semver commits with footers', t => {
AMENDED_VERSION_MESSAGES.forEach(message => t.true(isIgnored(message)));
});
test('should return true fixup commits', t => {
t.true(isIgnored('fixup! initial commit'));
});
test('should return true squash commits', t => {
t.true(isIgnored('squash! initial commit'));
});
test('should return true for bitbucket merge commits', t => {
t.true(
isIgnored('Merged in feature/facebook-friends-sync (pull request #8)')
);
t.true(isIgnored('Merged develop into feature/component-form-select-card'));
t.true(isIgnored('Automatic merge'));
});
test('should return true for automatic merge commits', t => {
t.true(isIgnored('Auto-merged develop into master'));
});
test('should return false for commits containing, but not starting, with merge branch', t => {
t.false(isIgnored('foo bar Merge branch xxx'));
});
test('should return false for ignored message if defaults is false', t => {
t.false(
isIgnored('Auto-merged develop into master', {
defaults: false
})
);
});
test('should return false for ignored message if custom ignores and defaults is false', t => {
t.false(
isIgnored('Auto-merged develop into master', {
defaults: false
})
);
});
test('should throw error if ignores is not an array', t => {
const ignoredString = 'this should be ignored';
t.throws(() => {
isIgnored(ignoredString, {
ignores: 'throws error'
});
});
});
test('should return true for custom ignores as function', t => {
const ignoredString = 'this should be ignored';
t.true(
isIgnored(ignoredString, {
ignores: [c => c === ignoredString]
})
);
});