forked from googleapis/release-please
-
Notifications
You must be signed in to change notification settings - Fork 0
/
semver.ts
101 lines (96 loc) · 3.39 KB
/
semver.ts
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
import {describe, it} from 'mocha';
import {SemverVersioningStrategy} from '../../src/versioning-strategies/semver';
import {ConventionalCommit} from '../../src';
import {Version} from '../../src/version';
import {expect} from 'chai';
const commit: ConventionalCommit = {
type: 'chore',
breaking: false,
notes: [],
references: [],
scope: '',
bareMessage: '',
sha: '',
message: '',
};
const g = (v: Partial<ConventionalCommit>) => ({...commit, ...v});
const COMMITS = {
major: [{type: 'feat'}, {}, {}, {breaking: true}].map(g),
minor: [{}, {}, {type: 'feat'}].map(g),
patch: [{}, {type: 'chore'}, {type: 'fix'}].map(g),
};
const checks = [
// Normal releases
['2.0.0', 'major', false, undefined, '3.0.0'],
['2.0.0', 'minor', false, undefined, '2.1.0'],
['2.0.0', 'patch', false, undefined, '2.0.1'],
// premajor -> normal
['2.0.0-pre.1', 'major', false, undefined, '2.0.0'],
['2.0.0-pre.5', 'minor', false, undefined, '2.0.0'],
['2.0.0-pre.4', 'patch', false, undefined, '2.0.0'],
// preminor -> normal
['2.1.0-pre.1', 'major', false, undefined, '3.0.0'],
['2.1.0-pre.5', 'minor', false, undefined, '2.1.0'],
['2.1.0-pre.4', 'patch', false, undefined, '2.1.0'],
// prepatch -> normal
['2.0.1-pre.1', 'major', false, undefined, '3.0.0'],
['2.0.1-pre.5', 'minor', false, undefined, '2.1.0'],
['2.0.1-pre.4', 'patch', false, undefined, '2.0.1'],
// Prereleases
['2.0.0', 'major', true, 'pre', '3.0.0-pre.0'],
['2.0.0', 'minor', true, 'pre', '2.1.0-pre.0'],
['2.0.0', 'patch', true, 'pre', '2.0.1-pre.0'],
// premajor - prereleases
['2.0.0-pre.1', 'major', true, undefined, '2.0.0-pre.2'],
['2.0.0-pre.1', 'minor', true, undefined, '2.0.0-pre.2'],
['2.0.0-pre.1', 'patch', true, undefined, '2.0.0-pre.2'],
// preminor - prereleases
['2.1.0-pre.1', 'major', true, undefined, '3.0.0-pre.0'],
['2.1.0-pre.1', 'minor', true, undefined, '2.1.0-pre.2'],
['2.1.0-pre.1', 'patch', true, undefined, '2.1.0-pre.2'],
// prepatch - prereleases
['2.0.1-pre.1', 'major', true, undefined, '3.0.0-pre.0'],
['2.0.1-pre.1', 'minor', true, undefined, '2.1.0-pre.0'],
['2.0.1-pre.1', 'patch', true, undefined, '2.0.1-pre.2'],
// different prerelease identifiers
['2.0.0-beta.1', 'major', true, undefined, '2.0.0-beta.2'],
['2.0.0-alpha.1', 'major', true, undefined, '2.0.0-alpha.2'],
['2.0.0-rc.1', 'major', true, undefined, '2.0.0-rc.2'],
['2.0.0-0', 'major', true, undefined, '2.0.0-1'],
// leaves prerelease
['2.0.0-beta.1', 'major', false, undefined, '2.0.0'],
['2.0.0-alpha.1', 'major', false, undefined, '2.0.0'],
['2.0.0-rc.1', 'major', false, undefined, '2.0.0'],
['2.0.0-0', 'major', false, undefined, '2.0.0'],
] satisfies [
string,
keyof typeof COMMITS,
boolean,
string | undefined,
string
][];
describe('SemverVersioningStrategy', () => {
for (const [
version,
commits,
prerelease,
prereleaseType,
expected,
] of checks) {
const name = [version, commits, prerelease, prereleaseType, expected];
const id = name
.map(v => (typeof v === 'undefined' ? 'undefined' : v))
.join(',');
it(`${id}`, () => {
const r = new SemverVersioningStrategy({prerelease, prereleaseType}).bump(
Version.parse(version),
COMMITS[commits]
);
expect(
`${r.major}.${r.minor}.${r.patch}${
r.preRelease ? `-${r.preRelease}` : ''
}`
).to.equal(expected, id);
});
}
});