/
nsisUpdaterTest.ts
360 lines (303 loc) · 11.9 KB
/
nsisUpdaterTest.ts
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
import { BitbucketPublisher } from "app-builder-lib/out/publish/BitbucketPublisher"
import { BitbucketOptions, GenericServerOptions, GithubOptions, KeygenOptions, S3Options, SpacesOptions } from "builder-util-runtime"
import { UpdateCheckResult } from "electron-updater"
import { outputFile } from "fs-extra"
import { tmpdir } from "os"
import * as path from "path"
import { assertThat } from "../helpers/fileAssert"
import { removeUnstableProperties } from "../helpers/packTester"
import { createNsisUpdater, trackEvents, validateDownload, writeUpdateConfig } from "../helpers/updaterTestUtil"
// some tests are flaky
jest.retryTimes(3)
if (process.env.ELECTRON_BUILDER_OFFLINE === "true") {
fit("Skip ArtifactPublisherTest suite — ELECTRON_BUILDER_OFFLINE is defined", () => {
console.warn("[SKIP] Skip ArtifactPublisherTest suite — ELECTRON_BUILDER_OFFLINE is defined")
})
}
test("downgrade (disallowed, beta)", async () => {
const updater = await createNsisUpdater("1.5.2-beta.4")
updater.updateConfigPath = await writeUpdateConfig<GithubOptions>({
provider: "github",
owner: "develar",
repo: "__test_nsis_release",
})
const actualEvents: Array<string> = []
const expectedEvents = ["checking-for-update", "update-not-available"]
for (const eventName of expectedEvents) {
updater.addListener(eventName, () => {
actualEvents.push(eventName)
})
}
const updateCheckResult = await updater.checkForUpdates()
expect(removeUnstableProperties(updateCheckResult?.updateInfo)).toMatchSnapshot()
// noinspection JSIgnoredPromiseFromCall
expect(updateCheckResult?.downloadPromise).toBeUndefined()
expect(actualEvents).toEqual(expectedEvents)
})
test("file url generic", async () => {
const updater = await createNsisUpdater()
updater.updateConfigPath = await writeUpdateConfig<GenericServerOptions>({
provider: "generic",
url: "https://develar.s3.amazonaws.com/test",
})
await validateDownload(updater)
})
test.ifEnv(process.env.KEYGEN_TOKEN)("file url keygen", async () => {
const updater = await createNsisUpdater()
updater.addAuthHeader(`Bearer ${process.env.KEYGEN_TOKEN}`)
updater.updateConfigPath = await writeUpdateConfig<KeygenOptions>({
provider: "keygen",
product: "43981278-96e7-47de-b8c2-98d59987206b",
account: "cdecda36-3ef0-483e-ad88-97e7970f3149",
})
await validateDownload(updater)
})
test.ifEnv(process.env.BITBUCKET_TOKEN)("file url bitbucket", async () => {
const updater = await createNsisUpdater()
const options: BitbucketOptions = {
provider: "bitbucket",
owner: "mike-m",
slug: "electron-builder-test",
}
updater.addAuthHeader(BitbucketPublisher.convertAppPassword(options.owner, process.env.BITBUCKET_TOKEN!))
updater.updateConfigPath = await writeUpdateConfig(options)
await validateDownload(updater)
})
test.skip("DigitalOcean Spaces", async () => {
const updater = await createNsisUpdater()
updater.updateConfigPath = await writeUpdateConfig<SpacesOptions>({
provider: "spaces",
name: "electron-builder-test",
path: "light-updater-test",
region: "nyc3",
})
await validateDownload(updater)
})
test.skip.ifNotCiWin("sha512 mismatch error event", async () => {
const updater = await createNsisUpdater()
updater.updateConfigPath = await writeUpdateConfig<GenericServerOptions>({
provider: "generic",
url: "https://develar.s3.amazonaws.com/test",
channel: "beta",
})
const actualEvents = trackEvents(updater)
const updateCheckResult = await updater.checkForUpdates()
expect(removeUnstableProperties(updateCheckResult?.updateInfo)).toMatchSnapshot()
await assertThat(updateCheckResult?.downloadPromise).throws()
expect(actualEvents).toMatchSnapshot()
})
test("file url generic - manual download", async () => {
const updater = await createNsisUpdater()
updater.updateConfigPath = await writeUpdateConfig<GenericServerOptions>({
provider: "generic",
url: "https://develar.s3.amazonaws.com/test",
})
updater.autoDownload = false
const actualEvents = trackEvents(updater)
const updateCheckResult = await updater.checkForUpdates()
expect(removeUnstableProperties(updateCheckResult?.updateInfo)).toMatchSnapshot()
// noinspection JSIgnoredPromiseFromCall
expect(updateCheckResult?.downloadPromise).toBeNull()
expect(actualEvents).toMatchSnapshot()
await assertThat(path.join((await updater.downloadUpdate())[0])).isFile()
})
// https://github.com/electron-userland/electron-builder/issues/1045
test("checkForUpdates several times", async () => {
const updater = await createNsisUpdater()
updater.updateConfigPath = await writeUpdateConfig<GenericServerOptions>({
provider: "generic",
url: "https://develar.s3.amazonaws.com/test",
})
const actualEvents = trackEvents(updater)
for (let i = 0; i < 10; i++) {
//noinspection JSIgnoredPromiseFromCall
void updater.checkForUpdates()
}
async function checkForUpdates() {
const updateCheckResult = await updater.checkForUpdates()
expect(removeUnstableProperties(updateCheckResult?.updateInfo)).toMatchSnapshot()
await checkDownloadPromise(updateCheckResult)
}
await checkForUpdates()
// we must not download the same file again
await checkForUpdates()
expect(actualEvents).toMatchSnapshot()
})
async function checkDownloadPromise(updateCheckResult: UpdateCheckResult | null) {
return await assertThat(path.join((await updateCheckResult?.downloadPromise)![0])).isFile()
}
test("file url github", async () => {
const updater = await createNsisUpdater()
const options: GithubOptions = {
provider: "github",
owner: "develar",
repo: "__test_nsis_release",
}
updater.updateConfigPath = await writeUpdateConfig(options)
updater.signals.updateDownloaded(info => {
expect(info.downloadedFile).not.toBeNull()
delete (info as any).downloadedFile
expect(info).toMatchSnapshot()
})
await validateDownload(updater)
})
test("file url github pre-release and fullChangelog", async () => {
const updater = await createNsisUpdater("1.5.0-beta.1")
const options: GithubOptions = {
provider: "github",
owner: "develar",
repo: "__test_nsis_release",
}
updater.fullChangelog = true
updater.updateConfigPath = await writeUpdateConfig(options)
updater.signals.updateDownloaded(info => {
expect(info.downloadedFile).not.toBeNull()
delete (info as any).downloadedFile
expect(info).toMatchSnapshot()
})
const updateCheckResult = await validateDownload(updater)
expect(updateCheckResult?.updateInfo).toMatchSnapshot()
})
test.ifEnv(process.env.GH_TOKEN || process.env.GITHUB_TOKEN)("file url github private", async () => {
const updater = await createNsisUpdater("0.0.1")
updater.updateConfigPath = await writeUpdateConfig<GithubOptions>({
provider: "github",
owner: "develar",
repo: "__test_nsis_release_private",
private: true,
})
await validateDownload(updater)
})
test("test error", async () => {
const updater = await createNsisUpdater("0.0.1")
const actualEvents = trackEvents(updater)
await assertThat(updater.checkForUpdates()).throws()
expect(actualEvents).toMatchSnapshot()
})
test.skip("test download progress", async () => {
const updater = await createNsisUpdater("0.0.1")
updater.updateConfigPath = await writeUpdateConfig({
provider: "generic",
url: "https://develar.s3.amazonaws.com/test",
})
updater.autoDownload = false
const progressEvents: Array<any> = []
updater.signals.progress(it => progressEvents.push(it))
await updater.checkForUpdates()
await updater.downloadUpdate()
expect(progressEvents.length).toBeGreaterThanOrEqual(1)
const lastEvent = progressEvents.pop()
expect(lastEvent.percent).toBe(100)
expect(lastEvent.bytesPerSecond).toBeGreaterThan(1)
expect(lastEvent.transferred).toBe(lastEvent.total)
})
test.ifAll("valid signature", async () => {
const updater = await createNsisUpdater("0.0.1")
updater.updateConfigPath = await writeUpdateConfig({
provider: "github",
owner: "develar",
repo: "__test_nsis_release",
publisherName: ["Vladimir Krivosheev"],
})
await validateDownload(updater)
})
test.ifAll("valid signature - multiple publisher DNs", async () => {
const updater = await createNsisUpdater("0.0.1")
updater.updateConfigPath = await writeUpdateConfig({
provider: "github",
owner: "develar",
repo: "__test_nsis_release",
publisherName: ["Foo Bar", "CN=Vladimir Krivosheev, O=Vladimir Krivosheev, L=Grunwald, S=Bayern, C=DE", "Bar Foo"],
})
await validateDownload(updater)
})
test.ifAll("valid signature using DN", async () => {
const updater = await createNsisUpdater("0.0.1")
updater.updateConfigPath = await writeUpdateConfig({
provider: "github",
owner: "develar",
repo: "__test_nsis_release",
publisherName: ["CN=Vladimir Krivosheev, O=Vladimir Krivosheev, L=Grunwald, S=Bayern, C=DE"],
})
await validateDownload(updater)
})
test.skip.ifAll("invalid signature", async () => {
const updater = await createNsisUpdater("0.0.1")
updater.updateConfigPath = await writeUpdateConfig({
provider: "github",
owner: "develar",
repo: "__test_nsis_release",
publisherName: ["Foo Bar"],
})
const actualEvents = trackEvents(updater)
await assertThat(updater.checkForUpdates().then((it): any => it?.downloadPromise)).throws()
expect(actualEvents).toMatchSnapshot()
})
// disable for now
test("90 staging percentage", async () => {
const userIdFile = path.join(tmpdir(), "electron-updater-test", "userData", ".updaterId")
await outputFile(userIdFile, "1wa70172-80f8-5cc4-8131-28f5e0edd2a1")
const updater = await createNsisUpdater("0.0.1")
updater.updateConfigPath = await writeUpdateConfig<S3Options>({
provider: "s3",
channel: "staging-percentage",
bucket: "develar",
path: "test",
})
await validateDownload(updater)
})
test("1 staging percentage", async () => {
const userIdFile = path.join(tmpdir(), "electron-updater-test", "userData", ".updaterId")
await outputFile(userIdFile, "12a70172-80f8-5cc4-8131-28f5e0edd2a1")
const updater = await createNsisUpdater("0.0.1")
updater.updateConfigPath = await writeUpdateConfig({
provider: "s3",
channel: "staging-percentage-small",
bucket: "develar",
path: "test",
})
await validateDownload(updater, false)
})
test("cancel download with progress", async () => {
const updater = await createNsisUpdater()
updater.updateConfigPath = await writeUpdateConfig({
provider: "generic",
url: "https://develar.s3.amazonaws.com/full-test",
})
const progressEvents: Array<any> = []
updater.signals.progress(it => progressEvents.push(it))
let cancelled = false
updater.signals.updateCancelled(() => (cancelled = true))
const checkResult = await updater.checkForUpdates()
checkResult?.cancellationToken!.cancel()
if (progressEvents.length > 0) {
const lastEvent = progressEvents[progressEvents.length - 1]
expect(lastEvent.percent).not.toBe(100)
expect(lastEvent.bytesPerSecond).toBeGreaterThan(1)
expect(lastEvent.transferred).not.toBe(lastEvent.total)
}
const downloadPromise = checkResult?.downloadPromise
await assertThat(downloadPromise).throws()
expect(cancelled).toBe(true)
})
test.ifAll("test download and install", async () => {
const updater = await createNsisUpdater()
updater.updateConfigPath = await writeUpdateConfig<GenericServerOptions>({
provider: "generic",
url: "https://develar.s3.amazonaws.com/test",
})
await validateDownload(updater)
const actualEvents = trackEvents(updater)
expect(actualEvents).toMatchObject([])
// await updater.quitAndInstall(true, false)
})
test.ifAll("test downloaded installer", async () => {
const updater = await createNsisUpdater()
updater.updateConfigPath = await writeUpdateConfig<GenericServerOptions>({
provider: "generic",
url: "https://develar.s3.amazonaws.com/test",
})
const actualEvents = trackEvents(updater)
expect(actualEvents).toMatchObject([])
// await updater.quitAndInstall(true, false)
})