forked from casmith/release-it-calver-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalver-plugin-tests.js
84 lines (71 loc) · 3.55 KB
/
calver-plugin-tests.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
import {expect} from 'chai';
import CalverPlugin from './calver-plugin.js';
const formatMonth = (date) => "" + (date.getMonth() + 1);
const formatYear = (date, fullYear = false) => "" + (date.getFullYear() - (fullYear ? 0 : 2000));
function versionFromDate(date, minor = 0, fullYear = false) {
return `${formatYear(date, fullYear)}.${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(`${formatYear(now)}.${formatMonth(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 acccept an increment option', function () {
const before = new Date();
before.setMonth(before.getMonth() - 2);
const latestVersion = versionFromDate(before);
const plugin = new CalverPlugin();
plugin.setContext({increment: 'minor'});
const incrementedVersion = plugin.getIncrementedVersion({latestVersion});
expect(incrementedVersion).to.equal(versionFromDate(before, 1));
});
it('should accept a format option', function () {
const now = new Date();
const latestVersion = versionFromDate(now, 0, true);
const plugin = new CalverPlugin();
plugin.setContext({format: 'yyyy.mm.minor'});
const incrementedVersion = plugin.getIncrementedVersion({latestVersion});
expect(incrementedVersion).to.equal(versionFromDate(now, 1, true));
});
it('should support alpha increment', function () {
const version = '2021.1.1.0-alpha.0';
const plugin = new CalverPlugin();
plugin.setContext({'increment': 'alpha', 'format': 'yyyy.mm.minor.patch'});
const incrementedVersion = plugin.getIncrementedVersion({latestVersion: version});
expect(incrementedVersion).to.equal('2021.1.1.0-alpha.1');
});
it('should support both calendar and semantic tags in increment', function () {
const now = new Date();
const latestVersion = '21.1.5';
const plugin = new CalverPlugin();
plugin.setContext({'increment': 'calendar.minor'});
const firstBump = plugin.getIncrementedVersion({latestVersion});
const secondBump = plugin.getIncrementedVersion({latestVersion: firstBump});
const incrementedVersions = [firstBump, secondBump];
const expectedVersions = [versionFromDate(now, 0), versionFromDate(now, 1)];
expect(incrementedVersions).deep.to.equal(expectedVersions);
});
it('should work by calling getIncrement()', function () {
const version = '2021.1.1.0';
const plugin = new CalverPlugin();
plugin.setContext({'increment': 'minor', 'format': 'yyyy.mm.minor.patch'});
const incrementedVersion = plugin.getIncrement({latestVersion: version});
expect(incrementedVersion).to.equal('2021.1.2.0');
});
it('should work by calling getIncrementedVersionCI()', function () {
const version = '2021.1.1.0';
const plugin = new CalverPlugin();
plugin.setContext({'increment': 'minor', 'format': 'yyyy.mm.minor.patch'});
const incrementedVersion = plugin.getIncrementedVersionCI({latestVersion: version});
expect(incrementedVersion).to.equal('2021.1.2.0');
});
});