-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathcalver-plugin-tests.js
More file actions
207 lines (180 loc) · 8.78 KB
/
Copy pathcalver-plugin-tests.js
File metadata and controls
207 lines (180 loc) · 8.78 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
201
202
203
204
205
206
207
import {expect} from 'chai';
import CalverPlugin from './calver-plugin.js';
const formatMonth = (date) => "" + (date.getUTCMonth() + 1);
const formatYear = (date) => "" + date.getUTCFullYear();
function versionFromDate(date, minor = 0) {
return `${formatYear(date)}.${formatMonth(date)}.${minor}`;
}
describe('plugin', function () {
it('should bump calendar when incrementing in a new month', function () {
const before = new Date();
before.setMonth(before.getMonth() - 2);
const latestVersion = versionFromDate(before);
const incrementedVersion = new CalverPlugin().getIncrementedVersion({latestVersion});
const now = new Date();
expect(incrementedVersion).to.equal(versionFromDate(now, 0));
});
it('should bump minor when incrementing twice in the same month', function () {
const now = new Date();
const incrementedVersion = new CalverPlugin().getIncrementedVersion({latestVersion: versionFromDate(now)});
expect(incrementedVersion).to.equal(versionFromDate(now, 1));
});
it('should accept a cycle option', function () {
const now = new Date();
const latestVersion = `${formatYear(now)}.0`;
const plugin = new CalverPlugin();
plugin.setContext({cycle: 'year'});
const incrementedVersion = plugin.getIncrementedVersion({latestVersion});
expect(incrementedVersion).to.equal(`${formatYear(now)}.1`);
});
it('should bump calendar with year cycle', function () {
const latestVersion = '2025.3';
const plugin = new CalverPlugin();
plugin.setContext({cycle: 'year'});
const incrementedVersion = plugin.getIncrementedVersion({latestVersion});
const now = new Date();
expect(incrementedVersion).to.equal(`${formatYear(now)}.0`);
});
it('should generate initial version when latestVersion is 0.0.0', function () {
const now = new Date();
const plugin = new CalverPlugin();
const incrementedVersion = plugin.getIncrementedVersion({latestVersion: '0.0.0'});
expect(incrementedVersion).to.equal(versionFromDate(now, 0));
});
it('should generate initial version when no latestVersion', function () {
const now = new Date();
const plugin = new CalverPlugin();
const incrementedVersion = plugin.getIncrementedVersion({});
expect(incrementedVersion).to.equal(versionFromDate(now, 0));
});
it('should map deprecated format option to month cycle', function () {
const now = new Date();
const version = versionFromDate(now);
const plugin = new CalverPlugin();
plugin.setContext({format: 'yyyy.mm.minor'});
const incrementedVersion = plugin.getIncrementedVersion({latestVersion: version});
expect(incrementedVersion).to.equal(versionFromDate(now, 1));
});
it('should map deprecated format option to year cycle', function () {
const now = new Date();
const latestVersion = `${formatYear(now)}.0`;
const plugin = new CalverPlugin();
plugin.setContext({format: 'yyyy.minor'});
const incrementedVersion = plugin.getIncrementedVersion({latestVersion});
expect(incrementedVersion).to.equal(`${formatYear(now)}.1`);
});
it('should bump day cycle when date changes', function () {
const now = new Date();
const formatDay = (date) => "" + date.getUTCDate();
const plugin = new CalverPlugin();
plugin.setContext({cycle: 'day'});
const latestVersion = '2025.9.15.0';
const incrementedVersion = plugin.getIncrementedVersion({latestVersion});
expect(incrementedVersion).to.equal(`${formatYear(now)}.${formatMonth(now)}.${formatDay(now)}.0`);
});
it('should bump day cycle minor on same day', function () {
const now = new Date();
const formatDay = (date) => "" + date.getUTCDate();
const plugin = new CalverPlugin();
plugin.setContext({cycle: 'day'});
const latestVersion = `${formatYear(now)}.${formatMonth(now)}.${formatDay(now)}.0`;
const incrementedVersion = plugin.getIncrementedVersion({latestVersion});
expect(incrementedVersion).to.equal(`${formatYear(now)}.${formatMonth(now)}.${formatDay(now)}.1`);
});
it('should map deprecated yyyy.0m.0d.minor format to day cycle', function () {
const now = new Date();
const formatDay = (date) => "" + date.getUTCDate();
const plugin = new CalverPlugin();
plugin.setContext({format: 'yyyy.0m.0d.minor'});
const latestVersion = '2025.9.15.0';
const incrementedVersion = plugin.getIncrementedVersion({latestVersion});
expect(incrementedVersion).to.equal(`${formatYear(now)}.${formatMonth(now)}.${formatDay(now)}.0`);
});
it('should support prefix option', function () {
const now = new Date();
const plugin = new CalverPlugin();
plugin.setContext({prefix: 'ui-'});
const latestVersion = `ui-${versionFromDate(now)}`;
const incrementedVersion = plugin.getIncrementedVersion({latestVersion});
expect(incrementedVersion).to.equal(`ui-${versionFromDate(now, 1)}`);
});
it('should add prefix to initial version', function () {
const now = new Date();
const plugin = new CalverPlugin();
plugin.setContext({prefix: 'ui-'});
const incrementedVersion = plugin.getIncrementedVersion({latestVersion: '0.0.0'});
expect(incrementedVersion).to.equal(`ui-${versionFromDate(now, 0)}`);
});
it('should add prefix when bumping calendar', function () {
const now = new Date();
const before = new Date();
before.setMonth(before.getMonth() - 2);
const plugin = new CalverPlugin();
plugin.setContext({prefix: 'api-'});
const latestVersion = `api-${versionFromDate(before)}`;
const incrementedVersion = plugin.getIncrementedVersion({latestVersion});
expect(incrementedVersion).to.equal(`api-${versionFromDate(now, 0)}`);
});
it('should migrate old dot-separated month format', function () {
const now = new Date();
const plugin = new CalverPlugin();
const incrementedVersion = plugin.getIncrementedVersion({latestVersion: versionFromDate(now, 4)});
expect(incrementedVersion).to.equal(versionFromDate(now, 5));
});
it('should migrate old dot-separated day format', function () {
const now = new Date();
const formatDay = (date) => "" + date.getUTCDate();
const plugin = new CalverPlugin();
plugin.setContext({cycle: 'day'});
const latestVersion = `${formatYear(now)}.${formatMonth(now)}.${formatDay(now)}.0`;
const incrementedVersion = plugin.getIncrementedVersion({latestVersion});
expect(incrementedVersion).to.equal(`${formatYear(now)}.${formatMonth(now)}.${formatDay(now)}.1`);
});
it('should migrate old 2-digit year format', function () {
const now = new Date();
const latestVersion = `${formatYear(now).slice(2)}.${formatMonth(now)}.4`;
const incrementedVersion = new CalverPlugin().getIncrementedVersion({latestVersion});
expect(incrementedVersion).to.equal(versionFromDate(now, 5));
});
it('should migrate old format with prefix', function () {
const now = new Date();
const plugin = new CalverPlugin();
plugin.setContext({prefix: 'ui-'});
const incrementedVersion = plugin.getIncrementedVersion({latestVersion: `ui-${versionFromDate(now, 4)}`});
expect(incrementedVersion).to.equal(`ui-${versionFromDate(now, 5)}`);
});
it('should handle dash-separated input format', function () {
const now = new Date();
const latestVersion = `${formatYear(now)}-${formatMonth(now)}.4`;
const incrementedVersion = new CalverPlugin().getIncrementedVersion({latestVersion});
expect(incrementedVersion).to.equal(versionFromDate(now, 5));
});
it('should output dash-separated format when separator is -', function () {
const now = new Date();
const plugin = new CalverPlugin();
plugin.setContext({separator: '-'});
const incrementedVersion = plugin.getIncrementedVersion({latestVersion: `${formatYear(now)}-${formatMonth(now)}.4`});
expect(incrementedVersion).to.equal(`${formatYear(now)}-${formatMonth(now)}.5`);
});
it('should output dash-separated initial version when separator is -', function () {
const now = new Date();
const plugin = new CalverPlugin();
plugin.setContext({separator: '-'});
const incrementedVersion = plugin.getIncrementedVersion({latestVersion: '0.0.0'});
expect(incrementedVersion).to.equal(`${formatYear(now)}-${formatMonth(now)}.0`);
});
it('should work by calling getIncrement()', function () {
const now = new Date();
const version = versionFromDate(now);
const plugin = new CalverPlugin();
const incrementedVersion = plugin.getIncrement({latestVersion: version});
expect(incrementedVersion).to.equal(versionFromDate(now, 1));
});
it('should work by calling getIncrementedVersionCI()', function () {
const now = new Date();
const version = versionFromDate(now);
const plugin = new CalverPlugin();
const incrementedVersion = plugin.getIncrementedVersionCI({latestVersion: version});
expect(incrementedVersion).to.equal(versionFromDate(now, 1));
});
});