|
| 1 | +var platforms = require("../lib/utils/platforms") |
| 2 | +var useragent = require("express-useragent") |
| 3 | + |
| 4 | +describe("Platforms", function () { |
| 5 | + describe("Detect", function () { |
| 6 | + test("should detect osx_64", function () { |
| 7 | + expect(platforms.detect("myapp-v0.25.1-darwin-x64.zip")).toEqual( |
| 8 | + platforms.OSX_64, |
| 9 | + ) |
| 10 | + expect(platforms.detect("myapp.dmg")).toEqual(platforms.OSX_64) |
| 11 | + }) |
| 12 | + |
| 13 | + test("should detect windows_32", function () { |
| 14 | + expect(platforms.detect("myapp-v0.25.1-win32-ia32.zip")).toEqual( |
| 15 | + platforms.WINDOWS_32, |
| 16 | + ) |
| 17 | + expect(platforms.detect("atom-1.0.9-delta.nupkg")).toEqual( |
| 18 | + platforms.WINDOWS_32, |
| 19 | + ) |
| 20 | + expect(platforms.detect("RELEASES")).toEqual(platforms.WINDOWS_32) |
| 21 | + }) |
| 22 | + |
| 23 | + test("should detect windows_64", function () { |
| 24 | + expect(platforms.detect("MyApp-x64.exe")).toEqual(platforms.WINDOWS_64) |
| 25 | + var chrome = useragent.parse( |
| 26 | + "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36", |
| 27 | + ) |
| 28 | + |
| 29 | + expect(platforms.detectPlatformByUserAgent(chrome)).toEqual( |
| 30 | + platforms.WINDOWS_64, |
| 31 | + ) |
| 32 | + var edge = useragent.parse( |
| 33 | + "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", |
| 34 | + ) |
| 35 | + expect(platforms.detectPlatformByUserAgent(edge)).toEqual( |
| 36 | + platforms.WINDOWS_64, |
| 37 | + ) |
| 38 | + }) |
| 39 | + |
| 40 | + test("should detect linux", function () { |
| 41 | + expect(platforms.detect("enterprise-amd64.tar.gz")).toEqual( |
| 42 | + platforms.LINUX_64, |
| 43 | + ) |
| 44 | + expect(platforms.detect("enterprise-amd64.tgz")).toEqual( |
| 45 | + platforms.LINUX_64, |
| 46 | + ) |
| 47 | + expect(platforms.detect("enterprise-ia32.tar.gz")).toEqual( |
| 48 | + platforms.LINUX_32, |
| 49 | + ) |
| 50 | + expect(platforms.detect("enterprise-ia32.tgz")).toEqual( |
| 51 | + platforms.LINUX_32, |
| 52 | + ) |
| 53 | + }) |
| 54 | + |
| 55 | + test("should detect debian_32", function () { |
| 56 | + expect(platforms.detect("atom-ia32.deb")).toEqual(platforms.LINUX_DEB_32) |
| 57 | + }) |
| 58 | + |
| 59 | + test("should detect debian_64", function () { |
| 60 | + expect(platforms.detect("atom-amd64.deb")).toEqual(platforms.LINUX_DEB_64) |
| 61 | + }) |
| 62 | + |
| 63 | + test("should detect rpm_32", function () { |
| 64 | + expect(platforms.detect("atom-ia32.rpm")).toEqual(platforms.LINUX_RPM_32) |
| 65 | + }) |
| 66 | + |
| 67 | + test("should detect rpm_64", function () { |
| 68 | + expect(platforms.detect("atom-amd64.rpm")).toEqual(platforms.LINUX_RPM_64) |
| 69 | + }) |
| 70 | + |
| 71 | + describe("Resolve", function () { |
| 72 | + var version = { |
| 73 | + platforms: [ |
| 74 | + { |
| 75 | + type: "osx_64", |
| 76 | + filename: "test-3.3.1-darwin.dmg", |
| 77 | + download_url: |
| 78 | + "https://api.github.com/repos/test/test2/releases/assets/793838", |
| 79 | + download_count: 2, |
| 80 | + }, |
| 81 | + { |
| 82 | + type: "osx_64", |
| 83 | + filename: "test-3.3.1-darwin-x64.zip", |
| 84 | + download_url: |
| 85 | + "https://api.github.com/repos/test/test2/releases/assets/793869", |
| 86 | + download_count: 0, |
| 87 | + }, |
| 88 | + { |
| 89 | + type: "windows_32", |
| 90 | + filename: "atom-1.0.9-delta.nupkg", |
| 91 | + size: 1457531, |
| 92 | + content_type: "application/zip", |
| 93 | + download_url: |
| 94 | + "https://api.github.com/repos/atom/atom/releases/assets/825732", |
| 95 | + download_count: 55844, |
| 96 | + }, |
| 97 | + { |
| 98 | + type: "windows_32", |
| 99 | + filename: "atom-1.0.9-full.nupkg", |
| 100 | + size: 78181725, |
| 101 | + content_type: "application/zip", |
| 102 | + download_url: |
| 103 | + "https://api.github.com/repos/atom/atom/releases/assets/825730", |
| 104 | + download_count: 26987, |
| 105 | + }, |
| 106 | + { |
| 107 | + type: "linux_32", |
| 108 | + filename: "atom-ia32.tar.gz", |
| 109 | + size: 71292506, |
| 110 | + content_type: "application/zip", |
| 111 | + download_url: |
| 112 | + "https://api.github.com/repos/atom/atom/releases/assets/825658", |
| 113 | + download_count: 2494, |
| 114 | + }, |
| 115 | + { |
| 116 | + type: "linux_64", |
| 117 | + filename: "atom-amd64.tar.gz", |
| 118 | + size: 71292506, |
| 119 | + content_type: "application/zip", |
| 120 | + download_url: |
| 121 | + "https://api.github.com/repos/atom/atom/releases/assets/825658", |
| 122 | + download_count: 2494, |
| 123 | + }, |
| 124 | + { |
| 125 | + type: "linux_rpm_32", |
| 126 | + filename: "atom-ia32.rpm", |
| 127 | + size: 71292506, |
| 128 | + content_type: "application/zip", |
| 129 | + download_url: |
| 130 | + "https://api.github.com/repos/atom/atom/releases/assets/825658", |
| 131 | + download_count: 2494, |
| 132 | + }, |
| 133 | + { |
| 134 | + type: "linux_rpm_64", |
| 135 | + filename: "atom-amd64.rpm", |
| 136 | + size: 71292506, |
| 137 | + content_type: "application/zip", |
| 138 | + download_url: |
| 139 | + "https://api.github.com/repos/atom/atom/releases/assets/825658", |
| 140 | + download_count: 2494, |
| 141 | + }, |
| 142 | + { |
| 143 | + type: "linux_deb_32", |
| 144 | + filename: "atom-ia32.deb", |
| 145 | + size: 71292506, |
| 146 | + content_type: "application/zip", |
| 147 | + download_url: |
| 148 | + "https://api.github.com/repos/atom/atom/releases/assets/825658", |
| 149 | + download_count: 2494, |
| 150 | + }, |
| 151 | + { |
| 152 | + type: "linux_deb_64", |
| 153 | + filename: "atom-amd64.deb", |
| 154 | + size: 71292506, |
| 155 | + content_type: "application/zip", |
| 156 | + download_url: |
| 157 | + "https://api.github.com/repos/atom/atom/releases/assets/825658", |
| 158 | + download_count: 2494, |
| 159 | + }, |
| 160 | + { |
| 161 | + type: "windows_32", |
| 162 | + filename: "atom-windows.zip", |
| 163 | + size: 79815714, |
| 164 | + content_type: "application/zip", |
| 165 | + download_url: |
| 166 | + "https://api.github.com/repos/atom/atom/releases/assets/825729", |
| 167 | + download_count: 463, |
| 168 | + }, |
| 169 | + { |
| 170 | + type: "windows_32", |
| 171 | + filename: "AtomSetup.exe", |
| 172 | + size: 78675720, |
| 173 | + content_type: "application/zip", |
| 174 | + download_url: |
| 175 | + "https://api.github.com/repos/atom/atom/releases/assets/825728", |
| 176 | + download_count: 5612, |
| 177 | + }, |
| 178 | + ], |
| 179 | + } |
| 180 | + |
| 181 | + test("should resolve to best platform", function () { |
| 182 | + expect(platforms.resolve(version, "osx").filename).toEqual( |
| 183 | + "test-3.3.1-darwin.dmg", |
| 184 | + ) |
| 185 | + expect(platforms.resolve(version, "win32").filename).toEqual( |
| 186 | + "AtomSetup.exe", |
| 187 | + ) |
| 188 | + expect(platforms.resolve(version, "linux_64").filename).toEqual( |
| 189 | + "atom-amd64.tar.gz", |
| 190 | + ) |
| 191 | + expect(platforms.resolve(version, "linux_32").filename).toEqual( |
| 192 | + "atom-ia32.tar.gz", |
| 193 | + ) |
| 194 | + expect(platforms.resolve(version, "linux_rpm_32").filename).toEqual( |
| 195 | + "atom-ia32.rpm", |
| 196 | + ) |
| 197 | + expect(platforms.resolve(version, "linux_rpm_64").filename).toEqual( |
| 198 | + "atom-amd64.rpm", |
| 199 | + ) |
| 200 | + expect(platforms.resolve(version, "linux_deb_32").filename).toEqual( |
| 201 | + "atom-ia32.deb", |
| 202 | + ) |
| 203 | + expect(platforms.resolve(version, "linux_deb_64").filename).toEqual( |
| 204 | + "atom-amd64.deb", |
| 205 | + ) |
| 206 | + }) |
| 207 | + |
| 208 | + test("should resolve to best platform with a preferred filetype", function () { |
| 209 | + expect( |
| 210 | + platforms.resolve(version, "osx", { |
| 211 | + filePreference: [".zip"], |
| 212 | + }).filename, |
| 213 | + ).toEqual("test-3.3.1-darwin-x64.zip") |
| 214 | + }) |
| 215 | + |
| 216 | + test("should resolve to best platform with a wanted filetype", function () { |
| 217 | + expect( |
| 218 | + platforms.resolve(version, "osx", { |
| 219 | + wanted: ".zip", |
| 220 | + }).filename, |
| 221 | + ).toEqual("test-3.3.1-darwin-x64.zip") |
| 222 | + }) |
| 223 | + }) |
| 224 | + }) |
| 225 | +}) |
0 commit comments