version-bump-spec.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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') && !(isCI && 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('throws error when bumping to beta from stable', () => {
  61. const version = 'v2.0.0'
  62. return expect(
  63. nextVersion('beta', version)
  64. ).to.be.rejectedWith('Cannot bump to beta from stable.')
  65. })
  66. it('bumps to beta from nightly', async () => {
  67. const version = 'v2.0.0-nightly.19950901'
  68. const next = await nextVersion('beta', version)
  69. const matches = next.match(betaPattern)
  70. expect(matches).to.have.lengthOf(1)
  71. })
  72. it('bumps to beta from beta', async () => {
  73. const version = 'v2.0.0-beta.8'
  74. const next = await nextVersion('beta', version)
  75. expect(next).to.equal('2.0.0-beta.9')
  76. })
  77. it('bumps to stable from beta', async () => {
  78. const version = 'v2.0.0-beta.1'
  79. const next = await nextVersion('stable', version)
  80. expect(next).to.equal('2.0.0')
  81. })
  82. it('bumps to stable from stable', async () => {
  83. const version = 'v2.0.0'
  84. const next = await nextVersion('stable', version)
  85. expect(next).to.equal('2.0.1')
  86. })
  87. it('bumps to minor from stable', async () => {
  88. const version = 'v2.0.0'
  89. const next = await nextVersion('minor', version)
  90. expect(next).to.equal('2.1.0')
  91. })
  92. it('bumps to stable from nightly', async () => {
  93. const version = 'v2.0.0-nightly.19950901'
  94. const next = await nextVersion('stable', version)
  95. expect(next).to.equal('2.0.0')
  96. })
  97. it('throws on an invalid version', () => {
  98. const version = 'vI.AM.INVALID'
  99. return expect(
  100. nextVersion('beta', version)
  101. ).to.be.rejectedWith(`Invalid current version: ${version}`)
  102. })
  103. it('throws on an invalid bump type', () => {
  104. const version = 'v2.0.0'
  105. return expect(
  106. nextVersion('WRONG', version)
  107. ).to.be.rejectedWith('Invalid bump type.')
  108. })
  109. })
  110. })