-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathanalyze-commit.test.js
121 lines (96 loc) · 3.27 KB
/
analyze-commit.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
const test = require('ava');
const analyzeCommit = require('../lib/analyze-commit');
test('Match breaking change', (t) => {
const commit = {
notes: [{title: 'BREAKING CHANGE', text: 'some breaking change'}],
};
t.is(analyzeCommit([{breaking: true, release: 'major'}], commit), 'major');
});
test('Match revert commit', (t) => {
const commit = {
revert: {header: 'Update: First feature', hash: '123'},
};
t.is(analyzeCommit([{revert: true, release: 'patch'}], commit), 'patch');
});
test('Match multiple criteria with breaking change', (t) => {
const commit = {
type: 'feat',
notes: [{title: 'BREAKING CHANGE', text: 'some breaking change'}],
};
t.is(analyzeCommit([{type: 'feat', breaking: true, release: 'major'}], commit), 'major');
});
test('Match multiple criteria with revert', (t) => {
const commit = {
type: 'feat',
revert: {header: 'Update: First feature', hash: '123'},
};
t.is(analyzeCommit([{type: 'feat', revert: true, release: 'major'}], commit), 'major');
});
test('Match multiple criteria', (t) => {
const commit = {type: 'feat', scope: 1};
t.is(analyzeCommit([{type: 'feat', scope: 1, release: 'major'}], commit), 'major');
});
test('Match only if all criteria are verified', (t) => {
const commit = {
type: 'fix',
notes: [{title: 'BREAKING CHANGE', text: 'some breaking change'}],
};
t.is(
analyzeCommit(
[
{type: 'fix', release: 'minor'},
{type: 'fix', breaking: true, release: 'major'},
],
commit
),
'major'
);
});
test('Return undefined if there is no match', (t) => {
const commit = {
type: 'fix',
notes: [{title: 'BREAKING CHANGE', text: 'some breaking change'}],
};
t.is(analyzeCommit([{type: 'feat', breaking: true, release: 'major'}], commit), undefined);
});
test('Return undefined for commit with falsy properties', (t) => {
const commit = {type: null};
t.is(analyzeCommit([{type: 'feat'}], commit), undefined);
});
test('Match with glob', (t) => {
const rules = [{type: 'docs', scope: 'b*', release: 'minor'}];
const match = {type: 'docs', scope: 'bar'};
const match2 = {type: 'docs', scope: 'baz'};
const notMatch = {type: 'docs', scope: 'foo'};
t.is(analyzeCommit(rules, match), 'minor');
t.is(analyzeCommit(rules, match2), 'minor');
t.is(analyzeCommit(rules, notMatch), undefined);
});
test('Match with catchall and undefined commit', (t) => {
t.is(analyzeCommit([{type: '*', release: 'patch'}], {type: null}), 'patch');
});
test('Return highest release type if multiple rules match', (t) => {
const commit = {
type: 'feat',
notes: [{title: 'BREAKING CHANGE', text: 'some breaking change'}],
};
t.is(
analyzeCommit(
[
{type: 'feat', release: 'minor'},
{breaking: true, release: 'minor'},
{type: 'feat', breaking: true, release: 'major'},
],
commit
),
'major'
);
});
test('Return "false" for release type if the matching rule has "release" set to "false"', (t) => {
const commit = {type: 'fix'};
t.is(analyzeCommit([{type: 'fix', release: false}], commit), false);
});
test('Return "null" for release type if the matching rule has "release" set to "null"', (t) => {
const commit = {type: 'fix'};
t.is(analyzeCommit([{type: 'fix', release: null}], commit), null);
});