UNPKG

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