version-bump-spec.ts 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. import { expect } from 'chai';
  2. import { GitProcess, IGitExecutionOptions, IGitResult } from 'dugite';
  3. import { nextVersion } from '../script/release/version-bumper';
  4. import * as utils from '../script/release/version-utils';
  5. import * as sinon from 'sinon';
  6. import { ifdescribe } from './lib/spec-helpers';
  7. class GitFake {
  8. branches: {
  9. [key: string]: string[],
  10. };
  11. constructor () {
  12. this.branches = {};
  13. }
  14. setBranch (channel: string): void {
  15. this.branches[channel] = [];
  16. }
  17. setVersion (channel: string, latestTag: string): void {
  18. const tags = [latestTag];
  19. if (channel === 'alpha') {
  20. const versionStrs = latestTag.split(`${channel}.`);
  21. const latest = parseInt(versionStrs[1]);
  22. for (let i = latest; i >= 1; i--) {
  23. tags.push(`${versionStrs[0]}${channel}.${latest - i}`);
  24. }
  25. }
  26. this.branches[channel] = tags;
  27. }
  28. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  29. exec (args: string[], path: string, options?: IGitExecutionOptions | undefined): Promise<IGitResult> {
  30. let stdout = '';
  31. const stderr = '';
  32. const exitCode = 0;
  33. // handle for promoting from current master HEAD
  34. let branch = 'stable';
  35. const v = (args[2] === 'HEAD') ? 'stable' : args[3];
  36. if (v.includes('nightly')) branch = 'nightly';
  37. if (v.includes('alpha')) branch = 'alpha';
  38. if (v.includes('beta')) branch = 'beta';
  39. if (!this.branches[branch]) this.setBranch(branch);
  40. stdout = this.branches[branch].join('\n');
  41. return Promise.resolve({ exitCode, stdout, stderr });
  42. }
  43. }
  44. describe('version-bumper', () => {
  45. describe('makeVersion', () => {
  46. it('makes a version with a period delimiter', () => {
  47. const components = {
  48. major: 2,
  49. minor: 0,
  50. patch: 0
  51. };
  52. const version = utils.makeVersion(components, '.');
  53. expect(version).to.equal('2.0.0');
  54. });
  55. it('makes a version with a period delimiter and a partial pre', () => {
  56. const components = {
  57. major: 2,
  58. minor: 0,
  59. patch: 0,
  60. pre: ['nightly', 12345678]
  61. };
  62. const version = utils.makeVersion(components, '.', utils.preType.PARTIAL);
  63. expect(version).to.equal('2.0.0.12345678');
  64. });
  65. it('makes a version with a period delimiter and a full pre', () => {
  66. const components = {
  67. major: 2,
  68. minor: 0,
  69. patch: 0,
  70. pre: ['nightly', 12345678]
  71. };
  72. const version = utils.makeVersion(components, '.', utils.preType.FULL);
  73. expect(version).to.equal('2.0.0-nightly.12345678');
  74. });
  75. });
  76. // On macOS Circle CI we don't have a real git environment due to running
  77. // gclient sync on a linux machine. These tests therefore don't run as expected.
  78. ifdescribe(!(process.platform === 'linux' && process.arch.indexOf('arm') === 0) && process.platform !== 'darwin')('nextVersion', () => {
  79. describe('bump versions', () => {
  80. const nightlyPattern = /[0-9.]*(-nightly.(\d{4})(\d{2})(\d{2}))$/g;
  81. const betaPattern = /[0-9.]*(-beta[0-9.]*)/g;
  82. it('bumps to nightly from stable', async () => {
  83. const version = 'v2.0.0';
  84. const next = await nextVersion('nightly', version);
  85. const matches = next.match(nightlyPattern);
  86. expect(matches).to.have.lengthOf(1);
  87. });
  88. it('bumps to nightly from beta', async () => {
  89. const version = 'v2.0.0-beta.1';
  90. const next = await nextVersion('nightly', version);
  91. const matches = next.match(nightlyPattern);
  92. expect(matches).to.have.lengthOf(1);
  93. });
  94. it('bumps to nightly from nightly', async () => {
  95. const version = 'v2.0.0-nightly.19950901';
  96. const next = await nextVersion('nightly', version);
  97. const matches = next.match(nightlyPattern);
  98. expect(matches).to.have.lengthOf(1);
  99. });
  100. it('bumps to a nightly version above our switch from N-0-x to N-x-y branch names', async () => {
  101. const version = 'v2.0.0-nightly.19950901';
  102. const next = await nextVersion('nightly', version);
  103. // If it starts with v8 then we didn't bump above the 8-x-y branch
  104. expect(next.startsWith('v8')).to.equal(false);
  105. });
  106. it('throws error when bumping to beta from stable', () => {
  107. const version = 'v2.0.0';
  108. return expect(
  109. nextVersion('beta', version)
  110. ).to.be.rejectedWith('Cannot bump to beta from stable.');
  111. });
  112. it('bumps to beta from nightly', async () => {
  113. const version = 'v2.0.0-nightly.19950901';
  114. const next = await nextVersion('beta', version);
  115. const matches = next.match(betaPattern);
  116. expect(matches).to.have.lengthOf(1);
  117. });
  118. it('bumps to beta from beta', async () => {
  119. const version = 'v2.0.0-beta.8';
  120. const next = await nextVersion('beta', version);
  121. expect(next).to.equal('2.0.0-beta.9');
  122. });
  123. it('bumps to beta from beta if the previous beta is at least beta.10', async () => {
  124. const version = 'v6.0.0-beta.15';
  125. const next = await nextVersion('beta', version);
  126. expect(next).to.equal('6.0.0-beta.16');
  127. });
  128. it('bumps to stable from beta', async () => {
  129. const version = 'v2.0.0-beta.1';
  130. const next = await nextVersion('stable', version);
  131. expect(next).to.equal('2.0.0');
  132. });
  133. it('bumps to stable from stable', async () => {
  134. const version = 'v2.0.0';
  135. const next = await nextVersion('stable', version);
  136. expect(next).to.equal('2.0.1');
  137. });
  138. it('bumps to minor from stable', async () => {
  139. const version = 'v2.0.0';
  140. const next = await nextVersion('minor', version);
  141. expect(next).to.equal('2.1.0');
  142. });
  143. it('bumps to stable from nightly', async () => {
  144. const version = 'v2.0.0-nightly.19950901';
  145. const next = await nextVersion('stable', version);
  146. expect(next).to.equal('2.0.0');
  147. });
  148. it('throws on an invalid version', () => {
  149. const version = 'vI.AM.INVALID';
  150. return expect(
  151. nextVersion('beta', version)
  152. ).to.be.rejectedWith(`Invalid current version: ${version}`);
  153. });
  154. it('throws on an invalid bump type', () => {
  155. const version = 'v2.0.0';
  156. return expect(
  157. nextVersion('WRONG', version)
  158. ).to.be.rejectedWith('Invalid bump type.');
  159. });
  160. });
  161. });
  162. // If we don't plan on continuing to support an alpha channel past Electron 15,
  163. // these tests will be removed. Otherwise, integrate into the bump versions tests
  164. describe('bump versions - alpha channel', () => {
  165. const alphaPattern = /[0-9.]*(-alpha[0-9.]*)/g;
  166. const betaPattern = /[0-9.]*(-beta[0-9.]*)/g;
  167. const sandbox = sinon.createSandbox();
  168. const gitFake = new GitFake();
  169. beforeEach(() => {
  170. const wrapper = (args: string[], path: string, options?: IGitExecutionOptions | undefined) => gitFake.exec(args, path, options);
  171. sandbox.replace(GitProcess, 'exec', wrapper);
  172. });
  173. afterEach(() => {
  174. gitFake.branches = {};
  175. sandbox.restore();
  176. });
  177. it('bumps to alpha from nightly', async () => {
  178. const version = 'v2.0.0-nightly.19950901';
  179. gitFake.setVersion('nightly', version);
  180. const next = await nextVersion('alpha', version);
  181. const matches = next.match(alphaPattern);
  182. expect(matches).to.have.lengthOf(1);
  183. });
  184. it('throws error when bumping to alpha from stable', () => {
  185. const version = 'v2.0.0';
  186. return expect(
  187. nextVersion('alpha', version)
  188. ).to.be.rejectedWith('Cannot bump to alpha from stable.');
  189. });
  190. it('bumps to alpha from alpha', async () => {
  191. const version = 'v2.0.0-alpha.8';
  192. gitFake.setVersion('alpha', version);
  193. const next = await nextVersion('alpha', version);
  194. expect(next).to.equal('2.0.0-alpha.9');
  195. });
  196. it('bumps to alpha from alpha if the previous alpha is at least alpha.10', async () => {
  197. const version = 'v6.0.0-alpha.15';
  198. gitFake.setVersion('alpha', version);
  199. const next = await nextVersion('alpha', version);
  200. expect(next).to.equal('6.0.0-alpha.16');
  201. });
  202. it('bumps to beta from alpha', async () => {
  203. const version = 'v2.0.0-alpha.8';
  204. gitFake.setVersion('alpha', version);
  205. const next = await nextVersion('beta', version);
  206. const matches = next.match(betaPattern);
  207. expect(matches).to.have.lengthOf(1);
  208. expect(next).to.equal('2.0.0-beta.1');
  209. });
  210. });
  211. });