index.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. var test = require('tape')
  2. var semver = require('semver')
  3. var getAbi = require('../index').getAbi
  4. var getTarget = require('../index').getTarget
  5. var getNextTarget = require('../index')._getNextTarget
  6. var allTargets = require('../index').allTargets
  7. test('getNextTarget gets the next unsopported target', function (t) {
  8. var mockTargets = [
  9. {runtime: 'node', target: '7.0.0', abi: '51', lts: false},
  10. {runtime: 'node', target: '8.0.0', abi: '57', lts: false},
  11. {runtime: 'electron', target: '0.36.0', abi: '47', lts: false},
  12. {runtime: 'electron', target: '1.1.0', abi: '48', lts: false}
  13. ]
  14. t.equal(getNextTarget('node', mockTargets), '9.0.0')
  15. t.equal(getNextTarget('electron', mockTargets), '1.2.0')
  16. t.end()
  17. })
  18. test('getTarget calculates correct Node target', function (t) {
  19. t.equal(getTarget(undefined), process.versions.node)
  20. t.equal(getTarget(null), process.versions.node)
  21. t.equal(getTarget('11'), '0.10.4')
  22. t.equal(getTarget('14'), '0.11.11')
  23. t.equal(getTarget('46'), '4.0.0')
  24. t.equal(getTarget('47'), '5.0.0')
  25. t.equal(getTarget('48'), '6.0.0')
  26. t.equal(getTarget('51'), '7.0.0')
  27. t.end()
  28. })
  29. test('getTarget calculates correct Electron target', function (t) {
  30. t.throws(getTarget.bind(null, '14', 'electron'))
  31. t.equal(getTarget('47', 'electron'), '0.36.0')
  32. t.equal(getTarget('48', 'electron'), '1.1.0')
  33. t.equal(getTarget('49', 'electron'), '1.3.0')
  34. t.equal(getTarget('50', 'electron'), '1.4.0')
  35. t.end()
  36. })
  37. test('getTarget calculates correct Node-Webkit target', function (t) {
  38. t.throws(getTarget.bind(null, '14', 'ode-webkit'))
  39. t.equal(getTarget('47', 'node-webkit'), '0.13.0')
  40. t.equal(getTarget('48', 'node-webkit'), '0.15.0')
  41. t.equal(getTarget('51', 'node-webkit'), '0.18.3')
  42. t.equal(getTarget('57', 'node-webkit'), '0.23.0')
  43. t.equal(getTarget('59', 'node-webkit'), '0.26.5')
  44. t.end()
  45. })
  46. test('getAbi calculates correct Node ABI', function (t) {
  47. t.equal(getAbi(undefined), process.versions.modules)
  48. t.equal(getAbi(null), process.versions.modules)
  49. t.throws(function () { getAbi('a.b.c') })
  50. t.throws(function () { getAbi(getNextTarget('node')) })
  51. t.equal(getAbi('7.2.0'), '51')
  52. t.equal(getAbi('7.0.0'), '51')
  53. t.equal(getAbi('6.9.9'), '48')
  54. t.equal(getAbi('6.0.0'), '48')
  55. t.equal(getAbi('5.9.9'), '47')
  56. t.equal(getAbi('5.0.0'), '47')
  57. t.equal(getAbi('4.9.9'), '46')
  58. t.equal(getAbi('4.0.0'), '46')
  59. t.equal(getAbi('0.12.17'), '14')
  60. t.equal(getAbi('0.12.0'), '14')
  61. t.equal(getAbi('0.11.16'), '14')
  62. t.equal(getAbi('0.11.11'), '14')
  63. t.equal(getAbi('0.11.10'), '13')
  64. t.equal(getAbi('0.11.8'), '13')
  65. t.equal(getAbi('0.11.7'), '0x000C')
  66. t.equal(getAbi('0.11.0'), '0x000C')
  67. t.equal(getAbi('0.10.48'), '11')
  68. t.equal(getAbi('0.10.30'), '11')
  69. t.equal(getAbi('0.10.4'), '11')
  70. t.equal(getAbi('0.10.3'), '0x000B')
  71. t.equal(getAbi('0.10.1'), '0x000B')
  72. t.equal(getAbi('0.10.0'), '0x000B')
  73. t.equal(getAbi('0.9.12'), '0x000B')
  74. t.equal(getAbi('0.9.9'), '0x000B')
  75. t.equal(getAbi('0.9.8'), '0x000A')
  76. t.equal(getAbi('0.9.1'), '0x000A')
  77. t.equal(getAbi('0.9.0'), '1')
  78. t.equal(getAbi('0.8.0'), '1')
  79. t.equal(getAbi('0.2.0'), '1')
  80. t.end()
  81. })
  82. test('getAbi calculates correct Electron ABI', function (t) {
  83. t.throws(function () { getAbi(undefined, 'electron') })
  84. t.throws(function () { getAbi(getNextTarget('electron'), 'electron') })
  85. t.equal(getAbi('9.0.0', 'electron'), '80')
  86. t.equal(getAbi('8.0.0', 'electron'), '76')
  87. t.equal(getAbi('7.0.0', 'electron'), '75')
  88. t.equal(getAbi('6.0.0', 'electron'), '73')
  89. t.equal(getAbi('5.0.0', 'electron'), '70')
  90. t.equal(getAbi('4.1.4', 'electron'), '69')
  91. t.equal(getAbi('4.0.4', 'electron'), '69')
  92. t.equal(getAbi('4.0.3', 'electron'), '64')
  93. t.equal(getAbi('3.1.8', 'electron'), '64')
  94. t.equal(getAbi('2.0.18', 'electron'), '57')
  95. t.equal(getAbi('1.4.0', 'electron'), '50')
  96. t.equal(getAbi('1.3.0', 'electron'), '49')
  97. t.equal(getAbi('1.2.0', 'electron'), '48')
  98. t.equal(getAbi('1.1.0', 'electron'), '48')
  99. t.equal(getAbi('1.0.0', 'electron'), '47')
  100. t.equal(getAbi('0.37.0', 'electron'), '47')
  101. t.equal(getAbi('0.36.0', 'electron'), '47')
  102. t.equal(getAbi('0.35.0', 'electron'), '46')
  103. t.equal(getAbi('0.34.0', 'electron'), '46')
  104. t.equal(getAbi('0.33.0', 'electron'), '46')
  105. t.equal(getAbi('0.32.0', 'electron'), '45')
  106. t.equal(getAbi('0.31.0', 'electron'), '45')
  107. t.equal(getAbi('0.30.0', 'electron'), '44')
  108. t.end()
  109. })
  110. test('getAbi calculates correct Node-Webkit ABI', function (t) {
  111. t.throws(function () { getAbi(undefined, 'node-webkit') })
  112. t.throws(function () { getAbi(getNextTarget('node-webkit'), 'node-webkit') })
  113. t.equal(getAbi('0.13.0', 'node-webkit'), '47')
  114. t.equal(getAbi('0.14.0', 'node-webkit'), '47')
  115. t.equal(getAbi('0.15.0', 'node-webkit'), '48')
  116. t.equal(getAbi('0.16.0', 'node-webkit'), '48')
  117. t.equal(getAbi('0.17.0', 'node-webkit'), '48')
  118. t.equal(getAbi('0.18.2', 'node-webkit'), '48')
  119. t.equal(getAbi('0.18.3', 'node-webkit'), '51')
  120. t.equal(getAbi('0.19.0', 'node-webkit'), '51')
  121. t.equal(getAbi('0.20.0', 'node-webkit'), '51')
  122. t.equal(getAbi('0.21.0', 'node-webkit'), '51')
  123. t.equal(getAbi('0.22.0', 'node-webkit'), '51')
  124. t.equal(getAbi('0.23.0', 'node-webkit'), '57')
  125. t.equal(getAbi('0.24.0', 'node-webkit'), '57')
  126. t.equal(getAbi('0.25.0', 'node-webkit'), '57')
  127. t.equal(getAbi('0.26.4', 'node-webkit'), '57')
  128. t.equal(getAbi('0.26.5', 'node-webkit'), '59')
  129. t.end()
  130. })
  131. test('getAbi supports leading v', function (t) {
  132. t.equal(getAbi('v7.2.0'), '51')
  133. t.end()
  134. })
  135. test('getAbi returns abi if passed as target', function (t) {
  136. t.equal(getAbi('57'), '57')
  137. t.end()
  138. })
  139. test('allTargets are sorted', function (t) {
  140. var electron = allTargets.filter(function (t) { return t.runtime === 'electron' })
  141. var node = allTargets.filter(function (t) { return t.runtime === 'node' })
  142. var nodeWebkit = allTargets.filter(function (t) { return t.runtime === 'node-webkit' })
  143. function sort (t1, t2) {
  144. return semver.compare(t1.target, t2.target)
  145. }
  146. t.deepEqual(electron, electron.slice().sort(sort))
  147. t.deepEqual(node, node.slice().sort(sort))
  148. t.deepEqual(nodeWebkit, nodeWebkit.slice().sort(sort))
  149. t.end()
  150. })