-
Notifications
You must be signed in to change notification settings - Fork 304
/
Copy pathplatforms.js
111 lines (98 loc) · 4.76 KB
/
platforms.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
var should = require('should');
var platforms = require('../lib/platforms');
var useragent = require('express-useragent');
describe('Platforms', function() {
describe('Detect', function() {
it('should detect osx_64', function() {
platforms.detect('myapp-v0.25.1-darwin-x64.zip').should.be.exactly(platforms.OSX_64);
platforms.detect('myapp.dmg').should.be.exactly(platforms.OSX_64);
});
it('should detect windows_32', function() {
platforms.detect('myapp-v0.25.1-win32-ia32.zip').should.be.exactly(platforms.WINDOWS_32);
platforms.detect('atom-1.0.9-delta.nupkg').should.be.exactly(platforms.WINDOWS_32);
platforms.detect('RELEASES').should.be.exactly(platforms.WINDOWS_32);
});
it('should detect windows_64', function() {
platforms.detect('MyApp-x64.exe').should.be.exactly(platforms.WINDOWS_64);
var chrome = useragent.parse('Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36')
platforms.detectPlatformByUserAgent(chrome).should.be.exactly(platforms.WINDOWS_64);
var edge = useragent.parse('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586')
platforms.detectPlatformByUserAgent(edge).should.be.exactly(platforms.WINDOWS_64);
});
it('should detect linux', function() {
platforms.detect('atom-amd64.deb').should.be.exactly(platforms.LINUX_64);
});
});
describe('Resolve', function() {
var version = {
platforms: [
{
"type": "osx_64",
"filename": "test-3.3.1-darwin.dmg",
"download_url": "https://api.github.com/repos/test/test2/releases/assets/793838",
"download_count": 2
},
{
"type": "osx_64",
"filename": "test-3.3.1-darwin-x64.zip",
"download_url": "https://api.github.com/repos/test/test2/releases/assets/793869",
"download_count": 0
},
{
"type": "windows_32",
"filename": "atom-1.0.9-delta.nupkg",
"size": 1457531,
"content_type": "application/zip",
"download_url": "https://api.github.com/repos/atom/atom/releases/assets/825732",
"download_count": 55844
},
{
"type": "windows_32",
"filename": "atom-1.0.9-full.nupkg",
"size": 78181725,
"content_type": "application/zip",
"download_url": "https://api.github.com/repos/atom/atom/releases/assets/825730",
"download_count": 26987
},
{
"type": "linux_64",
"filename": "atom-amd64.deb",
"size": 71292506,
"content_type": "application/zip",
"download_url": "https://api.github.com/repos/atom/atom/releases/assets/825658",
"download_count": 2494
},
{
"type": "windows_32",
"filename": "atom-windows.zip",
"size": 79815714,
"content_type": "application/zip",
"download_url": "https://api.github.com/repos/atom/atom/releases/assets/825729",
"download_count": 463
},
{
"type": "windows_32",
"filename": "AtomSetup.exe",
"size": 78675720,
"content_type": "application/zip",
"download_url": "https://api.github.com/repos/atom/atom/releases/assets/825728",
"download_count": 5612
}
]
};
it('should resolve to best platform', function() {
platforms.resolve(version, 'osx').filename.should.be.exactly("test-3.3.1-darwin.dmg"),
platforms.resolve(version, 'win32').filename.should.be.exactly("AtomSetup.exe")
});
it('should resolve to best platform with a preferred filetype', function() {
platforms.resolve(version, 'osx', {
filePreference: ['.zip']
}).filename.should.be.exactly("test-3.3.1-darwin-x64.zip")
});
it('should resolve to best platform with a wanted filetype', function() {
platforms.resolve(version, 'osx', {
wanted: '.zip'
}).filename.should.be.exactly("test-3.3.1-darwin-x64.zip")
});
})
});