version-bump-spec.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. const { expect } = require('chai')
  2. const { remote } = require('electron')
  3. const { nextVersion } = require('../script/bump-version')
  4. const utils = require('../script/lib/version-utils')
  5. const isCi = remote.getGlobal('isCi')
  6. // On macOS Circle CI we don't have a real git environment due to running
  7. // gclient sync on a linux machine. These tests therefore don't run as expected
  8. const describeFn = (isCi && process.platform === 'darwin') ? describe.skip : describe
  9. describeFn('bump-version utils', () => {
  10. it('makes a version with a period delimeter', () => {
  11. const components = {
  12. major: 2,
  13. minor: 0,
  14. patch: 0
  15. }
  16. const version = utils.makeVersion(components, '.')
  17. expect(version).to.equal('2.0.0')
  18. })
  19. it('makes a version with a period delimeter and a partial pre', () => {
  20. const components = {
  21. major: 2,
  22. minor: 0,
  23. patch: 0,
  24. pre: [ 'nightly', 12345678 ]
  25. }
  26. const version = utils.makeVersion(components, '.', utils.preType.PARTIAL)
  27. expect(version).to.equal('2.0.0.12345678')
  28. })
  29. it('makes a version with a period delimeter and a full pre', () => {
  30. const components = {
  31. major: 2,
  32. minor: 0,
  33. patch: 0,
  34. pre: [ 'nightly', 12345678 ]
  35. }
  36. const version = utils.makeVersion(components, '.', utils.preType.FULL)
  37. expect(version).to.equal('2.0.0-nightly.12345678')
  38. })
  39. })
  40. describeFn('bump-version script', () => {
  41. const nightlyPattern = /[0-9.]*(-nightly.(\d{4})(\d{2})(\d{2}))$/g
  42. const betaPattern = /[0-9.]*(-beta[0-9.]*)/g
  43. before(function () {
  44. if (process.platform === 'linux' && process.arch === 'arm') {
  45. this.skip()
  46. }
  47. })
  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('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 stable from nightly', async () => {
  94. const version = 'v2.0.0-nightly.19950901'
  95. const next = await nextVersion('stable', version)
  96. expect(next).to.equal('2.0.0')
  97. })
  98. it('throws on an invalid version', () => {
  99. const version = 'vI.AM.INVALID'
  100. return expect(
  101. nextVersion('beta', version)
  102. ).to.be.rejectedWith(`Invalid current version: ${version}`)
  103. })
  104. it('throws on an invalid bump type', () => {
  105. const version = 'v2.0.0'
  106. return expect(
  107. nextVersion('WRONG', version)
  108. ).to.be.rejectedWith('Invalid bump type.')
  109. })
  110. })