version-bump-spec.ts 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. ifdescribe(!(process.platform === 'linux' && process.arch.indexOf('arm') === 0) && process.platform !== 'darwin')('nextVersion', () => {
  77. describe('bump versions', () => {
  78. const nightlyPattern = /[0-9.]*(-nightly.(\d{4})(\d{2})(\d{2}))$/g;
  79. const betaPattern = /[0-9.]*(-beta[0-9.]*)/g;
  80. it('bumps to nightly from stable', async () => {
  81. const version = 'v2.0.0';
  82. const next = await nextVersion('nightly', version);
  83. const matches = next.match(nightlyPattern);
  84. expect(matches).to.have.lengthOf(1);
  85. });
  86. it('bumps to nightly from beta', async () => {
  87. const version = 'v2.0.0-beta.1';
  88. const next = await nextVersion('nightly', version);
  89. const matches = next.match(nightlyPattern);
  90. expect(matches).to.have.lengthOf(1);
  91. });
  92. it('bumps to nightly from nightly', async () => {
  93. const version = 'v2.0.0-nightly.19950901';
  94. const next = await nextVersion('nightly', version);
  95. const matches = next.match(nightlyPattern);
  96. expect(matches).to.have.lengthOf(1);
  97. });
  98. it('bumps to a nightly version above our switch from N-0-x to N-x-y branch names', async () => {
  99. const version = 'v2.0.0-nightly.19950901';
  100. const next = await nextVersion('nightly', version);
  101. // If it starts with v8 then we didn't bump above the 8-x-y branch
  102. expect(next.startsWith('v8')).to.equal(false);
  103. });
  104. it('throws error when bumping to beta from stable', () => {
  105. const version = 'v2.0.0';
  106. return expect(
  107. nextVersion('beta', version)
  108. ).to.be.rejectedWith('Cannot bump to beta from stable.');
  109. });
  110. it('bumps to beta from nightly', async () => {
  111. const version = 'v2.0.0-nightly.19950901';
  112. const next = await nextVersion('beta', version);
  113. const matches = next.match(betaPattern);
  114. expect(matches).to.have.lengthOf(1);
  115. });
  116. it('bumps to beta from beta', async () => {
  117. const version = 'v2.0.0-beta.8';
  118. const next = await nextVersion('beta', version);
  119. expect(next).to.equal('2.0.0-beta.9');
  120. });
  121. it('bumps to beta from beta if the previous beta is at least beta.10', async () => {
  122. const version = 'v6.0.0-beta.15';
  123. const next = await nextVersion('beta', version);
  124. expect(next).to.equal('6.0.0-beta.16');
  125. });
  126. it('bumps to stable from beta', async () => {
  127. const version = 'v2.0.0-beta.1';
  128. const next = await nextVersion('stable', version);
  129. expect(next).to.equal('2.0.0');
  130. });
  131. it('bumps to stable from stable', async () => {
  132. const version = 'v2.0.0';
  133. const next = await nextVersion('stable', version);
  134. expect(next).to.equal('2.0.1');
  135. });
  136. it('bumps to minor from stable', async () => {
  137. const version = 'v2.0.0';
  138. const next = await nextVersion('minor', version);
  139. expect(next).to.equal('2.1.0');
  140. });
  141. it('bumps to stable from nightly', async () => {
  142. const version = 'v2.0.0-nightly.19950901';
  143. const next = await nextVersion('stable', version);
  144. expect(next).to.equal('2.0.0');
  145. });
  146. it('throws on an invalid version', () => {
  147. const version = 'vI.AM.INVALID';
  148. return expect(
  149. nextVersion('beta', version)
  150. ).to.be.rejectedWith(`Invalid current version: ${version}`);
  151. });
  152. it('throws on an invalid bump type', () => {
  153. const version = 'v2.0.0';
  154. return expect(
  155. nextVersion('WRONG', version)
  156. ).to.be.rejectedWith('Invalid bump type.');
  157. });
  158. });
  159. });
  160. // If we don't plan on continuing to support an alpha channel past Electron 15,
  161. // these tests will be removed. Otherwise, integrate into the bump versions tests
  162. describe('bump versions - alpha channel', () => {
  163. const alphaPattern = /[0-9.]*(-alpha[0-9.]*)/g;
  164. const betaPattern = /[0-9.]*(-beta[0-9.]*)/g;
  165. const sandbox = sinon.createSandbox();
  166. const gitFake = new GitFake();
  167. beforeEach(() => {
  168. const wrapper = (args: string[], path: string, options?: IGitExecutionOptions | undefined) => gitFake.exec(args, path, options);
  169. sandbox.replace(GitProcess, 'exec', wrapper);
  170. });
  171. afterEach(() => {
  172. gitFake.branches = {};
  173. sandbox.restore();
  174. });
  175. it('bumps to alpha from nightly', async () => {
  176. const version = 'v2.0.0-nightly.19950901';
  177. gitFake.setVersion('nightly', version);
  178. const next = await nextVersion('alpha', version);
  179. const matches = next.match(alphaPattern);
  180. expect(matches).to.have.lengthOf(1);
  181. });
  182. it('throws error when bumping to alpha from stable', () => {
  183. const version = 'v2.0.0';
  184. return expect(
  185. nextVersion('alpha', version)
  186. ).to.be.rejectedWith('Cannot bump to alpha from stable.');
  187. });
  188. it('bumps to alpha from alpha', async () => {
  189. const version = 'v2.0.0-alpha.8';
  190. gitFake.setVersion('alpha', version);
  191. const next = await nextVersion('alpha', version);
  192. expect(next).to.equal('2.0.0-alpha.9');
  193. });
  194. it('bumps to alpha from alpha if the previous alpha is at least alpha.10', async () => {
  195. const version = 'v6.0.0-alpha.15';
  196. gitFake.setVersion('alpha', version);
  197. const next = await nextVersion('alpha', version);
  198. expect(next).to.equal('6.0.0-alpha.16');
  199. });
  200. it('bumps to beta from alpha', async () => {
  201. const version = 'v2.0.0-alpha.8';
  202. gitFake.setVersion('alpha', version);
  203. const next = await nextVersion('beta', version);
  204. const matches = next.match(betaPattern);
  205. expect(matches).to.have.lengthOf(1);
  206. expect(next).to.equal('2.0.0-beta.1');
  207. });
  208. });
  209. });