-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
174 lines (148 loc) · 4.22 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
'use strict'
var test = require('tape')
var shuffle = require('array-shuffle')
var parseTags = require('.').parseTags
var matchTags = require('.').matchTags
var compareTags = require('.').compareTags
var parseTuple = require('.').parseTuple
var matchTuple = require('.').matchTuple
var compareTuples = require('.').compareTuples
test('parse tags', function (t) {
t.is(parseTags('ignored'), undefined)
t.is(parseTags('node.ignored'), undefined)
t.is(parseTags('node.node').runtime, 'node')
t.is(parseTags('electron.node').runtime, 'electron')
t.is(parseTags('node-webkit.node').runtime, 'node-webkit')
t.same(parseTags('node.napi.node'), {
file: 'node.napi.node',
runtime: 'node',
napi: true,
specificity: 2
})
t.same(parseTags('node.abi64.uv1.armv7.musl.node'), {
file: 'node.abi64.uv1.armv7.musl.node',
runtime: 'node',
abi: '64',
uv: '1',
armv: '7',
libc: 'musl',
specificity: 5
})
t.end()
})
test('sort tags', function (t) {
check('electron', [
'electron.abi64.uv1.node',
'electron.napi.uv1.armv7.musl.node',
'electron.napi.uv1.musl.node',
'node.abi64.uv1.node',
'node.abi64.node',
'node.napi.uv1.armv7.musl.node',
'node.napi.uv1.node'
], 'sort order ok')
check('node', [
'node.abi64.uv1.node',
'node.abi64.node',
'node.napi.uv1.armv7.musl.node',
'node.napi.uv1.node',
'electron.abi64.uv1.node',
'electron.napi.uv1.armv7.musl.node',
'electron.napi.uv1.musl.node'
], 'same files, different runtime')
function check (runtime, sorted, message) {
t.same(
shuffle(sorted)
.map(parseTags)
.sort(compareTags(runtime))
.map(getFile),
sorted,
message
)
}
t.end()
})
test('match and sort tags', function (t) {
check('electron', '64', [
'node.abi64.node',
'electron.napi.node'
], [
'electron.napi.node'
], 'dont use a node abi for electron')
check('electron', '64', [
'node.abi64.node',
'node.napi.node'
], [
'node.napi.node'
], 'but do use a node napi for electron')
check('electron', '64', [
'node.abi64.node',
'node.napi.node',
'electron.abi64.node',
'electron.abi99.node',
'electron.napi.node'
], [
'electron.abi64.node',
'electron.napi.node',
'node.napi.node'
], 'except if an electron abi is available')
check('node', '64', [
'electron.napi.node',
'electron.abi64.node',
'node.abi64.node'
], [
'node.abi64.node'
], 'never use electron for node')
function check (runtime, abi, files, expected, message) {
t.same(
files
.map(parseTags)
.filter(matchTags(runtime, abi))
.sort(compareTags(runtime))
.map(getFile),
expected,
message
)
}
t.end()
})
test('parse tuples', function (t) {
t.same(parseTuple('linux-arm64'), {
name: 'linux-arm64',
platform: 'linux',
architectures: ['arm64']
})
t.same(parseTuple('darwin-x64+arm64'), {
name: 'darwin-x64+arm64',
platform: 'darwin',
architectures: ['x64', 'arm64']
})
// Should skip invalid tuples
t.is(parseTuple(''), undefined)
t.is(parseTuple('linux-'), undefined)
t.is(parseTuple('-arm64'), undefined)
t.is(parseTuple('linux-arm64+'), undefined)
t.is(parseTuple('linux-arm64++x64'), undefined)
t.is(parseTuple('linux-+arm64'), undefined)
t.end()
})
test('sort tuples', function (t) {
var tuples = ['darwin-arm64+x64+ia32', 'darwin-x64', 'darwin-x64+arm64']
var sorted = tuples.map(parseTuple).sort(compareTuples).map(getTupleName)
t.same(sorted, ['darwin-x64', 'darwin-x64+arm64', 'darwin-arm64+x64+ia32'])
t.end()
})
test('match tuples', function (t) {
var tuples = ['linux-arm64', 'darwin-x64+arm64', 'darwin-x64'].map(parseTuple)
t.is(tuples.filter(matchTuple('darwin', 'x64')).sort(compareTuples)[0].name, 'darwin-x64')
t.is(tuples.filter(matchTuple('darwin', 'arm64')).sort(compareTuples)[0].name, 'darwin-x64+arm64')
t.is(tuples.filter(matchTuple('linux', 'arm64')).sort(compareTuples)[0].name, 'linux-arm64')
t.is(tuples.some(matchTuple('linux', 'other')), false)
t.is(tuples.some(matchTuple('other', 'arm64')), false)
t.end()
})
function getTupleName (tuple) {
return tuple.name
}
function getFile (tags) {
return tags.file
}