From a457d0d9d559499eb6164d9c54ecc466b25e91a2 Mon Sep 17 00:00:00 2001 From: develar Date: Mon, 12 Dec 2016 09:06:35 +0100 Subject: [PATCH] fix(electron-auto-updater): load default provider only if custom was not set --- nsis-auto-updater/package.json | 2 +- nsis-auto-updater/src/NsisUpdater.ts | 25 ++++++------------------- test/src/nsisUpdaterTest.ts | 16 ++-------------- 3 files changed, 9 insertions(+), 34 deletions(-) diff --git a/nsis-auto-updater/package.json b/nsis-auto-updater/package.json index 360b6b9f392..e6ba19735a8 100644 --- a/nsis-auto-updater/package.json +++ b/nsis-auto-updater/package.json @@ -1,6 +1,6 @@ { "name": "electron-auto-updater", - "version": "0.7.0", + "version": "0.7.1", "description": "NSIS Auto Updater", "main": "out/nsis-auto-updater/src/main.js", "author": "Vladimir Krivosheev", diff --git a/nsis-auto-updater/src/NsisUpdater.ts b/nsis-auto-updater/src/NsisUpdater.ts index 1eeed41b0bf..b04ff024359 100644 --- a/nsis-auto-updater/src/NsisUpdater.ts +++ b/nsis-auto-updater/src/NsisUpdater.ts @@ -30,10 +30,7 @@ export class NsisUpdater extends EventEmitter { this.app = (global).__test_app || require("electron").app - if (options == null) { - this.clientPromise = this.loadUpdateConfig() - } - else { + if (options != null) { this.setFeedURL(options) } } @@ -47,15 +44,11 @@ export class NsisUpdater extends EventEmitter { } async checkForUpdates(): Promise { - if (this.clientPromise == null) { - const message = "Update URL is not set" - const error = new Error(message) - this.emit("error", error, message) - throw error - } - this.emit("checking-for-update") try { + if (this.clientPromise == null) { + this.clientPromise = NsisUpdater.loadUpdateConfig() + } return await this.doCheckForUpdates() } catch (e) { @@ -157,14 +150,8 @@ export class NsisUpdater extends EventEmitter { return true } - async loadUpdateConfig() { - try { - return createClient(safeLoad(await readFile(path.join((global).__test_resourcesPath || (process).resourcesPath, "app-update.yml"), "utf-8"))) - } - catch (e) { - this.emit("error", e, (e.stack || e).toString()) - throw e - } + private static async loadUpdateConfig() { + return createClient(safeLoad(await readFile(path.join((global).__test_resourcesPath || (process).resourcesPath, "app-update.yml"), "utf-8"))) } } diff --git a/test/src/nsisUpdaterTest.ts b/test/src/nsisUpdaterTest.ts index 692aaac0bb0..38bde95babd 100644 --- a/test/src/nsisUpdaterTest.ts +++ b/test/src/nsisUpdaterTest.ts @@ -5,7 +5,6 @@ import { TmpDir } from "out/util/tmp" import { outputFile } from "fs-extra-p" import { safeDump } from "js-yaml" import { GenericServerOptions, GithubOptions } from "out/options/publishOptions" -import BluebirdPromise from "bluebird-lst-c" if (process.env.ELECTRON_BUILDER_OFFLINE === "true") { fit("Skip ArtifactPublisherTest suite — ELECTRON_BUILDER_OFFLINE is defined", () => { @@ -134,7 +133,7 @@ test("test error", async () => { const updater: NsisUpdater = new NsisUpdaterClass() const actualEvents: Array = [] - const expectedEvents = ["checking-for-update", "error"] + const expectedEvents = ["checking-for-update", "error", "error"] for (const eventName of expectedEvents) { updater.addListener(eventName, () => { actualEvents.push(eventName) @@ -142,16 +141,5 @@ test("test error", async () => { } await assertThat(updater.checkForUpdates()).throws("Path must be a string. Received undefined") - await new BluebirdPromise(function (resolve, reject) { - setTimeout(() => { - try { - expect(actualEvents).toEqual(expectedEvents) - } - catch (e) { - reject(e) - } - - resolve() - }, 500) - }) + expect(actualEvents).toEqual(expectedEvents) }) \ No newline at end of file