-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
124 lines (107 loc) · 2.66 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
'use strict'
var test = require('tape')
var shuffle = require('array-shuffle')
var parseTags = require('.').parseTags
var matchTags = require('.').matchTags
var compareTags = require('.').compareTags
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()
})
function getFile (tags) {
return tags.file
}