version-bump-spec.ts 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 './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. // TODO ELECTRON 15: Re-enable after Electron 15 alpha has released
  113. it.skip('bumps to beta from nightly', async () => {
  114. const version = 'v2.0.0-nightly.19950901';
  115. const next = await nextVersion('beta', version);
  116. const matches = next.match(betaPattern);
  117. expect(matches).to.have.lengthOf(1);
  118. });
  119. it('bumps to beta from beta', async () => {
  120. const version = 'v2.0.0-beta.8';
  121. const next = await nextVersion('beta', version);
  122. expect(next).to.equal('2.0.0-beta.9');
  123. });
  124. it('bumps to beta from beta if the previous beta is at least beta.10', async () => {
  125. const version = 'v6.0.0-beta.15';
  126. const next = await nextVersion('beta', version);
  127. expect(next).to.equal('6.0.0-beta.16');
  128. });
  129. it('bumps to stable from beta', async () => {
  130. const version = 'v2.0.0-beta.1';
  131. const next = await nextVersion('stable', version);
  132. expect(next).to.equal('2.0.0');
  133. });
  134. it('bumps to stable from stable', async () => {
  135. const version = 'v2.0.0';
  136. const next = await nextVersion('stable', version);
  137. expect(next).to.equal('2.0.1');
  138. });
  139. it('bumps to minor from stable', async () => {
  140. const version = 'v2.0.0';
  141. const next = await nextVersion('minor', version);
  142. expect(next).to.equal('2.1.0');
  143. });
  144. it('bumps to stable from nightly', async () => {
  145. const version = 'v2.0.0-nightly.19950901';
  146. const next = await nextVersion('stable', version);
  147. expect(next).to.equal('2.0.0');
  148. });
  149. it('throws on an invalid version', () => {
  150. const version = 'vI.AM.INVALID';
  151. return expect(
  152. nextVersion('beta', version)
  153. ).to.be.rejectedWith(`Invalid current version: ${version}`);
  154. });
  155. it('throws on an invalid bump type', () => {
  156. const version = 'v2.0.0';
  157. return expect(
  158. nextVersion('WRONG', version)
  159. ).to.be.rejectedWith('Invalid bump type.');
  160. });
  161. });
  162. });
  163. // If we don't plan on continuing to support an alpha channel past Electron 15,
  164. // these tests will be removed. Otherwise, integrate into the bump versions tests
  165. describe('bump versions - alpha channel', () => {
  166. const alphaPattern = /[0-9.]*(-alpha[0-9.]*)/g;
  167. const betaPattern = /[0-9.]*(-beta[0-9.]*)/g;
  168. const sandbox = sinon.createSandbox();
  169. const gitFake = new GitFake();
  170. beforeEach(() => {
  171. const wrapper = (args: string[], path: string, options?: IGitExecutionOptions | undefined) => gitFake.exec(args, path, options);
  172. sandbox.replace(GitProcess, 'exec', wrapper);
  173. });
  174. afterEach(() => {
  175. gitFake.branches = {};
  176. sandbox.restore();
  177. });
  178. it('bumps to alpha from nightly', async () => {
  179. const version = 'v2.0.0-nightly.19950901';
  180. gitFake.setVersion('nightly', version);
  181. const next = await nextVersion('alpha', version);
  182. const matches = next.match(alphaPattern);
  183. expect(matches).to.have.lengthOf(1);
  184. });
  185. it('throws error when bumping to alpha from stable', () => {
  186. const version = 'v2.0.0';
  187. return expect(
  188. nextVersion('alpha', version)
  189. ).to.be.rejectedWith('Cannot bump to alpha from stable.');
  190. });
  191. it('bumps to alpha from alpha', async () => {
  192. const version = 'v2.0.0-alpha.8';
  193. gitFake.setVersion('alpha', version);
  194. const next = await nextVersion('alpha', version);
  195. expect(next).to.equal('2.0.0-alpha.9');
  196. });
  197. it('bumps to alpha from alpha if the previous alpha is at least alpha.10', async () => {
  198. const version = 'v6.0.0-alpha.15';
  199. gitFake.setVersion('alpha', version);
  200. const next = await nextVersion('alpha', version);
  201. expect(next).to.equal('6.0.0-alpha.16');
  202. });
  203. it('bumps to beta from alpha', async () => {
  204. const version = 'v2.0.0-alpha.8';
  205. gitFake.setVersion('alpha', version);
  206. const next = await nextVersion('beta', version);
  207. const matches = next.match(betaPattern);
  208. expect(matches).to.have.lengthOf(1);
  209. expect(next).to.equal('2.0.0-beta.1');
  210. });
  211. });
  212. });