version-bump-spec.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 === 'arm') && 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 stable from beta', async () => {
  84. const version = 'v2.0.0-beta.1';
  85. const next = await nextVersion('stable', version);
  86. expect(next).to.equal('2.0.0');
  87. });
  88. it('bumps to stable from stable', async () => {
  89. const version = 'v2.0.0';
  90. const next = await nextVersion('stable', version);
  91. expect(next).to.equal('2.0.1');
  92. });
  93. it('bumps to minor from stable', async () => {
  94. const version = 'v2.0.0';
  95. const next = await nextVersion('minor', version);
  96. expect(next).to.equal('2.1.0');
  97. });
  98. it('bumps to stable from nightly', async () => {
  99. const version = 'v2.0.0-nightly.19950901';
  100. const next = await nextVersion('stable', version);
  101. expect(next).to.equal('2.0.0');
  102. });
  103. it('throws on an invalid version', () => {
  104. const version = 'vI.AM.INVALID';
  105. return expect(
  106. nextVersion('beta', version)
  107. ).to.be.rejectedWith(`Invalid current version: ${version}`);
  108. });
  109. it('throws on an invalid bump type', () => {
  110. const version = 'v2.0.0';
  111. return expect(
  112. nextVersion('WRONG', version)
  113. ).to.be.rejectedWith('Invalid bump type.');
  114. });
  115. });
  116. });