version-bump-spec.ts 7.2 KB

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