forked from electron/electron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version-bump-spec.ts
251 lines (211 loc) · 8.34 KB
/
version-bump-spec.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
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
import { expect } from 'chai';
import { GitProcess, IGitExecutionOptions, IGitResult } from 'dugite';
import { nextVersion } from '../script/release/version-bumper';
import * as utils from '../script/release/version-utils';
import * as sinon from 'sinon';
import { ifdescribe } from './lib/spec-helpers';
class GitFake {
branches: {
[key: string]: string[],
};
constructor () {
this.branches = {};
}
setBranch (channel: string): void {
this.branches[channel] = [];
}
setVersion (channel: string, latestTag: string): void {
const tags = [latestTag];
if (channel === 'alpha') {
const versionStrs = latestTag.split(`${channel}.`);
const latest = parseInt(versionStrs[1]);
for (let i = latest; i >= 1; i--) {
tags.push(`${versionStrs[0]}${channel}.${latest - i}`);
}
}
this.branches[channel] = tags;
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
exec (args: string[], path: string, options?: IGitExecutionOptions | undefined): Promise<IGitResult> {
let stdout = '';
const stderr = '';
const exitCode = 0;
// handle for promoting from current master HEAD
let branch = 'stable';
const v = (args[2] === 'HEAD') ? 'stable' : args[3];
if (v.includes('nightly')) branch = 'nightly';
if (v.includes('alpha')) branch = 'alpha';
if (v.includes('beta')) branch = 'beta';
if (!this.branches[branch]) this.setBranch(branch);
stdout = this.branches[branch].join('\n');
return Promise.resolve({ exitCode, stdout, stderr });
}
}
describe('version-bumper', () => {
describe('makeVersion', () => {
it('makes a version with a period delimiter', () => {
const components = {
major: 2,
minor: 0,
patch: 0
};
const version = utils.makeVersion(components, '.');
expect(version).to.equal('2.0.0');
});
it('makes a version with a period delimiter and a partial pre', () => {
const components = {
major: 2,
minor: 0,
patch: 0,
pre: ['nightly', 12345678]
};
const version = utils.makeVersion(components, '.', utils.preType.PARTIAL);
expect(version).to.equal('2.0.0.12345678');
});
it('makes a version with a period delimiter and a full pre', () => {
const components = {
major: 2,
minor: 0,
patch: 0,
pre: ['nightly', 12345678]
};
const version = utils.makeVersion(components, '.', utils.preType.FULL);
expect(version).to.equal('2.0.0-nightly.12345678');
});
});
// On macOS Circle CI we don't have a real git environment due to running
// gclient sync on a linux machine. These tests therefore don't run as expected.
ifdescribe(!(process.platform === 'linux' && process.arch.indexOf('arm') === 0) && process.platform !== 'darwin')('nextVersion', () => {
describe('bump versions', () => {
const nightlyPattern = /[0-9.]*(-nightly.(\d{4})(\d{2})(\d{2}))$/g;
const betaPattern = /[0-9.]*(-beta[0-9.]*)/g;
it('bumps to nightly from stable', async () => {
const version = 'v2.0.0';
const next = await nextVersion('nightly', version);
const matches = next.match(nightlyPattern);
expect(matches).to.have.lengthOf(1);
});
it('bumps to nightly from beta', async () => {
const version = 'v2.0.0-beta.1';
const next = await nextVersion('nightly', version);
const matches = next.match(nightlyPattern);
expect(matches).to.have.lengthOf(1);
});
it('bumps to nightly from nightly', async () => {
const version = 'v2.0.0-nightly.19950901';
const next = await nextVersion('nightly', version);
const matches = next.match(nightlyPattern);
expect(matches).to.have.lengthOf(1);
});
it('bumps to a nightly version above our switch from N-0-x to N-x-y branch names', async () => {
const version = 'v2.0.0-nightly.19950901';
const next = await nextVersion('nightly', version);
// If it starts with v8 then we didn't bump above the 8-x-y branch
expect(next.startsWith('v8')).to.equal(false);
});
it('throws error when bumping to beta from stable', () => {
const version = 'v2.0.0';
return expect(
nextVersion('beta', version)
).to.be.rejectedWith('Cannot bump to beta from stable.');
});
it('bumps to beta from nightly', async () => {
const version = 'v2.0.0-nightly.19950901';
const next = await nextVersion('beta', version);
const matches = next.match(betaPattern);
expect(matches).to.have.lengthOf(1);
});
it('bumps to beta from beta', async () => {
const version = 'v2.0.0-beta.8';
const next = await nextVersion('beta', version);
expect(next).to.equal('2.0.0-beta.9');
});
it('bumps to beta from beta if the previous beta is at least beta.10', async () => {
const version = 'v6.0.0-beta.15';
const next = await nextVersion('beta', version);
expect(next).to.equal('6.0.0-beta.16');
});
it('bumps to stable from beta', async () => {
const version = 'v2.0.0-beta.1';
const next = await nextVersion('stable', version);
expect(next).to.equal('2.0.0');
});
it('bumps to stable from stable', async () => {
const version = 'v2.0.0';
const next = await nextVersion('stable', version);
expect(next).to.equal('2.0.1');
});
it('bumps to minor from stable', async () => {
const version = 'v2.0.0';
const next = await nextVersion('minor', version);
expect(next).to.equal('2.1.0');
});
it('bumps to stable from nightly', async () => {
const version = 'v2.0.0-nightly.19950901';
const next = await nextVersion('stable', version);
expect(next).to.equal('2.0.0');
});
it('throws on an invalid version', () => {
const version = 'vI.AM.INVALID';
return expect(
nextVersion('beta', version)
).to.be.rejectedWith(`Invalid current version: ${version}`);
});
it('throws on an invalid bump type', () => {
const version = 'v2.0.0';
return expect(
nextVersion('WRONG', version)
).to.be.rejectedWith('Invalid bump type.');
});
});
});
// If we don't plan on continuing to support an alpha channel past Electron 15,
// these tests will be removed. Otherwise, integrate into the bump versions tests
describe('bump versions - alpha channel', () => {
const alphaPattern = /[0-9.]*(-alpha[0-9.]*)/g;
const betaPattern = /[0-9.]*(-beta[0-9.]*)/g;
const sandbox = sinon.createSandbox();
const gitFake = new GitFake();
beforeEach(() => {
const wrapper = (args: string[], path: string, options?: IGitExecutionOptions | undefined) => gitFake.exec(args, path, options);
sandbox.replace(GitProcess, 'exec', wrapper);
});
afterEach(() => {
gitFake.branches = {};
sandbox.restore();
});
it('bumps to alpha from nightly', async () => {
const version = 'v2.0.0-nightly.19950901';
gitFake.setVersion('nightly', version);
const next = await nextVersion('alpha', version);
const matches = next.match(alphaPattern);
expect(matches).to.have.lengthOf(1);
});
it('throws error when bumping to alpha from stable', () => {
const version = 'v2.0.0';
return expect(
nextVersion('alpha', version)
).to.be.rejectedWith('Cannot bump to alpha from stable.');
});
it('bumps to alpha from alpha', async () => {
const version = 'v2.0.0-alpha.8';
gitFake.setVersion('alpha', version);
const next = await nextVersion('alpha', version);
expect(next).to.equal('2.0.0-alpha.9');
});
it('bumps to alpha from alpha if the previous alpha is at least alpha.10', async () => {
const version = 'v6.0.0-alpha.15';
gitFake.setVersion('alpha', version);
const next = await nextVersion('alpha', version);
expect(next).to.equal('6.0.0-alpha.16');
});
it('bumps to beta from alpha', async () => {
const version = 'v2.0.0-alpha.8';
gitFake.setVersion('alpha', version);
const next = await nextVersion('beta', version);
const matches = next.match(betaPattern);
expect(matches).to.have.lengthOf(1);
expect(next).to.equal('2.0.0-beta.1');
});
});
});