version-bump-spec.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import { expect } from 'chai';
  2. import { nextVersion } from '../script/release/version-bumper';
  3. import * as utils from '../script/release/version-utils';
  4. import { ifdescribe } from './spec-helpers';
  5. describe('version-bumper', () => {
  6. describe('makeVersion', () => {
  7. it('makes a version with a period delimeter', () => {
  8. const components = {
  9. major: 2,
  10. minor: 0,
  11. patch: 0
  12. };
  13. const version = utils.makeVersion(components, '.');
  14. expect(version).to.equal('2.0.0');
  15. });
  16. it('makes a version with a period delimeter and a partial pre', () => {
  17. const components = {
  18. major: 2,
  19. minor: 0,
  20. patch: 0,
  21. pre: ['nightly', 12345678]
  22. };
  23. const version = utils.makeVersion(components, '.', utils.preType.PARTIAL);
  24. expect(version).to.equal('2.0.0.12345678');
  25. });
  26. it('makes a version with a period delimeter and a full pre', () => {
  27. const components = {
  28. major: 2,
  29. minor: 0,
  30. patch: 0,
  31. pre: ['nightly', 12345678]
  32. };
  33. const version = utils.makeVersion(components, '.', utils.preType.FULL);
  34. expect(version).to.equal('2.0.0-nightly.12345678');
  35. });
  36. });
  37. // On macOS Circle CI we don't have a real git environment due to running
  38. // gclient sync on a linux machine. These tests therefore don't run as expected.
  39. ifdescribe(!(process.platform === 'linux' && process.arch.indexOf('arm') === 0) && process.platform !== 'darwin')('nextVersion', () => {
  40. const nightlyPattern = /[0-9.]*(-nightly.(\d{4})(\d{2})(\d{2}))$/g;
  41. const betaPattern = /[0-9.]*(-beta[0-9.]*)/g;
  42. it('bumps to nightly from stable', async () => {
  43. const version = 'v2.0.0';
  44. const next = await nextVersion('nightly', version);
  45. const matches = next.match(nightlyPattern);
  46. expect(matches).to.have.lengthOf(1);
  47. });
  48. it('bumps to nightly from beta', async () => {
  49. const version = 'v2.0.0-beta.1';
  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 nightly', async () => {
  55. const version = 'v2.0.0-nightly.19950901';
  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 a nightly version above our switch from N-0-x to N-x-y branch names', async () => {
  61. const version = 'v2.0.0-nightly.19950901';
  62. const next = await nextVersion('nightly', version);
  63. // If it starts with v8 then we didn't bump above the 8-x-y branch
  64. expect(next.startsWith('v8')).to.equal(false);
  65. });
  66. it('throws error when bumping to beta from stable', () => {
  67. const version = 'v2.0.0';
  68. return expect(
  69. nextVersion('beta', version)
  70. ).to.be.rejectedWith('Cannot bump to beta from stable.');
  71. });
  72. it('bumps to beta from nightly', async () => {
  73. const version = 'v2.0.0-nightly.19950901';
  74. const next = await nextVersion('beta', version);
  75. const matches = next.match(betaPattern);
  76. expect(matches).to.have.lengthOf(1);
  77. });
  78. it('bumps to beta from beta', async () => {
  79. const version = 'v2.0.0-beta.8';
  80. const next = await nextVersion('beta', version);
  81. expect(next).to.equal('2.0.0-beta.9');
  82. });
  83. it('bumps to beta from beta if the previous beta is at least beta.10', async () => {
  84. const version = 'v6.0.0-beta.10';
  85. const next = await nextVersion('beta', version);
  86. // Last 6.0.0 beta we did was beta.15
  87. // So we expect a beta.16 here
  88. expect(next).to.equal('6.0.0-beta.16');
  89. });
  90. it('bumps to stable from beta', async () => {
  91. const version = 'v2.0.0-beta.1';
  92. const next = await nextVersion('stable', version);
  93. expect(next).to.equal('2.0.0');
  94. });
  95. it('bumps to stable from stable', async () => {
  96. const version = 'v2.0.0';
  97. const next = await nextVersion('stable', version);
  98. expect(next).to.equal('2.0.1');
  99. });
  100. it('bumps to minor from stable', async () => {
  101. const version = 'v2.0.0';
  102. const next = await nextVersion('minor', version);
  103. expect(next).to.equal('2.1.0');
  104. });
  105. it('bumps to stable from nightly', async () => {
  106. const version = 'v2.0.0-nightly.19950901';
  107. const next = await nextVersion('stable', version);
  108. expect(next).to.equal('2.0.0');
  109. });
  110. it('throws on an invalid version', () => {
  111. const version = 'vI.AM.INVALID';
  112. return expect(
  113. nextVersion('beta', version)
  114. ).to.be.rejectedWith(`Invalid current version: ${version}`);
  115. });
  116. it('throws on an invalid bump type', () => {
  117. const version = 'v2.0.0';
  118. return expect(
  119. nextVersion('WRONG', version)
  120. ).to.be.rejectedWith('Invalid bump type.');
  121. });
  122. });
  123. });