version-bump-spec.ts 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. import { expect } from 'chai';
  2. import { nextVersion, shouldUpdateSupported, updateSupported } from '../script/release/version-bumper';
  3. import * as utils from '../script/release/version-utils';
  4. import { ifdescribe } from './spec-helpers';
  5. const { promises: fs } = require('fs');
  6. const path = require('path');
  7. const fixtureDir = path.resolve(__dirname, 'fixtures', 'version-bumper', 'fixture_support.md');
  8. const readFile = fs.readFile;
  9. const writeFile = fs.writeFile;
  10. describe('version-bumper', () => {
  11. describe('makeVersion', () => {
  12. it('makes a version with a period delimeter', () => {
  13. const components = {
  14. major: 2,
  15. minor: 0,
  16. patch: 0
  17. };
  18. const version = utils.makeVersion(components, '.');
  19. expect(version).to.equal('2.0.0');
  20. });
  21. it('makes a version with a period delimeter and a partial pre', () => {
  22. const components = {
  23. major: 2,
  24. minor: 0,
  25. patch: 0,
  26. pre: ['nightly', 12345678]
  27. };
  28. const version = utils.makeVersion(components, '.', utils.preType.PARTIAL);
  29. expect(version).to.equal('2.0.0.12345678');
  30. });
  31. it('makes a version with a period delimeter and a full pre', () => {
  32. const components = {
  33. major: 2,
  34. minor: 0,
  35. patch: 0,
  36. pre: ['nightly', 12345678]
  37. };
  38. const version = utils.makeVersion(components, '.', utils.preType.FULL);
  39. expect(version).to.equal('2.0.0-nightly.12345678');
  40. });
  41. });
  42. describe('updateSupported', () => {
  43. let restore: any;
  44. before(async () => {
  45. restore = await readFile(fixtureDir, 'utf8');
  46. });
  47. afterEach(async () => {
  48. await writeFile(fixtureDir, restore, 'utf8');
  49. });
  50. it('updates correctly when a new stable version is promoted from beta', async () => {
  51. const version = '4.0.0';
  52. const currentVersion = '4.0.0-beta.29';
  53. if (shouldUpdateSupported('stable', currentVersion, version)) {
  54. await updateSupported(version, fixtureDir);
  55. }
  56. const contents = await readFile(fixtureDir, 'utf8');
  57. expect(contents).to.contain('4.x.y\n* 3.x.y\n* 2.x.y');
  58. });
  59. it('should not update when a new stable patch version is promoted', async () => {
  60. const version = '3.0.1';
  61. const currentVersion = '3.0.0';
  62. if (shouldUpdateSupported('stable', currentVersion, version)) {
  63. await updateSupported(version, fixtureDir);
  64. }
  65. const contents = await readFile(fixtureDir, 'utf8');
  66. expect(contents).to.contain('3.x.y\n* 2.x.y\n* 1.x.y');
  67. });
  68. it('should not update when a new stable minor version is promoted', async () => {
  69. const version = '3.1.0';
  70. const currentVersion = '3.0.0';
  71. if (shouldUpdateSupported('minor', currentVersion, version)) {
  72. await updateSupported(version, fixtureDir);
  73. }
  74. const contents = await readFile(fixtureDir, 'utf8');
  75. expect(contents).to.contain('3.x.y\n* 2.x.y\n* 1.x.y');
  76. });
  77. it('should not update when a new beta.1 version is promoted', async () => {
  78. const version = '5.0.0-beta.1';
  79. const currentVersion = '4.0.0-beta.29';
  80. if (shouldUpdateSupported('beta', currentVersion, version)) {
  81. await updateSupported(version, fixtureDir);
  82. }
  83. const contents = await readFile(fixtureDir, 'utf8');
  84. expect(contents).to.contain('3.x.y\n* 2.x.y\n* 1.x.y');
  85. });
  86. it('should not update when a new beta.12 version is promoted', async () => {
  87. const version = '4.0.0-beta.12';
  88. const currentVersion = '4.0.0-beta.11';
  89. if (shouldUpdateSupported('beta', currentVersion, version)) {
  90. await updateSupported(version, fixtureDir);
  91. }
  92. const contents = await readFile(fixtureDir, 'utf8');
  93. expect(contents).to.contain('3.x.y\n* 2.x.y\n* 1.x.y');
  94. });
  95. it('should update when a new major nightly version is promoted', async () => {
  96. const version = '4.0.0-nightly.19950901';
  97. const currentVersion = '3.0.0-nightly.19950828';
  98. if (shouldUpdateSupported('nightly', currentVersion, version)) {
  99. await updateSupported(version, fixtureDir);
  100. }
  101. const contents = await readFile(fixtureDir, 'utf8');
  102. expect(contents).to.contain('4.x.y\n* 3.x.y\n* 2.x.y');
  103. });
  104. it('should not update when a new nightly version is promoted', async () => {
  105. const version = '3.0.0-nightly.19950901';
  106. const currentVersion = '3.0.0-nightly.19950828';
  107. if (shouldUpdateSupported('nightly', currentVersion, version)) {
  108. await updateSupported(version, fixtureDir);
  109. }
  110. const contents = await readFile(fixtureDir, 'utf8');
  111. expect(contents).to.contain('3.x.y\n* 2.x.y\n* 1.x.y');
  112. });
  113. });
  114. // On macOS Circle CI we don't have a real git environment due to running
  115. // gclient sync on a linux machine. These tests therefore don't run as expected.
  116. ifdescribe(!(process.platform === 'linux' && process.arch === 'arm') && process.platform !== 'darwin')('nextVersion', () => {
  117. const nightlyPattern = /[0-9.]*(-nightly.(\d{4})(\d{2})(\d{2}))$/g;
  118. const betaPattern = /[0-9.]*(-beta[0-9.]*)/g;
  119. it('bumps to nightly from stable', async () => {
  120. const version = 'v2.0.0';
  121. const next = await nextVersion('nightly', version);
  122. const matches = next.match(nightlyPattern);
  123. expect(matches).to.have.lengthOf(1);
  124. });
  125. it('bumps to nightly from beta', async () => {
  126. const version = 'v2.0.0-beta.1';
  127. const next = await nextVersion('nightly', version);
  128. const matches = next.match(nightlyPattern);
  129. expect(matches).to.have.lengthOf(1);
  130. });
  131. it('bumps to nightly from nightly', async () => {
  132. const version = 'v2.0.0-nightly.19950901';
  133. const next = await nextVersion('nightly', version);
  134. const matches = next.match(nightlyPattern);
  135. expect(matches).to.have.lengthOf(1);
  136. });
  137. it('bumps to a nightly version above our switch from N-0-x to N-x-y branch names', async () => {
  138. const version = 'v2.0.0-nightly.19950901';
  139. const next = await nextVersion('nightly', version);
  140. // If it starts with v8 then we didn't bump above the 8-x-y branch
  141. expect(next.startsWith('v8')).to.equal(false);
  142. });
  143. it('throws error when bumping to beta from stable', () => {
  144. const version = 'v2.0.0';
  145. return expect(
  146. nextVersion('beta', version)
  147. ).to.be.rejectedWith('Cannot bump to beta from stable.');
  148. });
  149. it('bumps to beta from nightly', async () => {
  150. const version = 'v2.0.0-nightly.19950901';
  151. const next = await nextVersion('beta', version);
  152. const matches = next.match(betaPattern);
  153. expect(matches).to.have.lengthOf(1);
  154. });
  155. it('bumps to beta from beta', async () => {
  156. const version = 'v2.0.0-beta.8';
  157. const next = await nextVersion('beta', version);
  158. expect(next).to.equal('2.0.0-beta.9');
  159. });
  160. it('bumps to beta from beta if the previous beta is at least beta.10', async () => {
  161. const version = 'v6.0.0-beta.10';
  162. const next = await nextVersion('beta', version);
  163. // Last 6.0.0 beta we did was beta.15
  164. // So we expect a beta.16 here
  165. expect(next).to.equal('6.0.0-beta.16');
  166. });
  167. it('bumps to stable from beta', async () => {
  168. const version = 'v2.0.0-beta.1';
  169. const next = await nextVersion('stable', version);
  170. expect(next).to.equal('2.0.0');
  171. });
  172. it('bumps to stable from stable', async () => {
  173. const version = 'v2.0.0';
  174. const next = await nextVersion('stable', version);
  175. expect(next).to.equal('2.0.1');
  176. });
  177. it('bumps to minor from stable', async () => {
  178. const version = 'v2.0.0';
  179. const next = await nextVersion('minor', version);
  180. expect(next).to.equal('2.1.0');
  181. });
  182. it('bumps to stable from nightly', async () => {
  183. const version = 'v2.0.0-nightly.19950901';
  184. const next = await nextVersion('stable', version);
  185. expect(next).to.equal('2.0.0');
  186. });
  187. it('throws on an invalid version', () => {
  188. const version = 'vI.AM.INVALID';
  189. return expect(
  190. nextVersion('beta', version)
  191. ).to.be.rejectedWith(`Invalid current version: ${version}`);
  192. });
  193. it('throws on an invalid bump type', () => {
  194. const version = 'v2.0.0';
  195. return expect(
  196. nextVersion('WRONG', version)
  197. ).to.be.rejectedWith('Invalid bump type.');
  198. });
  199. });
  200. });