Skip to content

Commit

Permalink
fix(electron-auto-updater): load default provider only if custom was …
Browse files Browse the repository at this point in the history
…not set
  • Loading branch information
develar committed Dec 12, 2016
1 parent 4faa3fb commit a457d0d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 34 deletions.
2 changes: 1 addition & 1 deletion nsis-auto-updater/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
25 changes: 6 additions & 19 deletions nsis-auto-updater/src/NsisUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ export class NsisUpdater extends EventEmitter {

this.app = (<any>global).__test_app || require("electron").app

if (options == null) {
this.clientPromise = this.loadUpdateConfig()
}
else {
if (options != null) {
this.setFeedURL(options)
}
}
Expand All @@ -47,15 +44,11 @@ export class NsisUpdater extends EventEmitter {
}

async checkForUpdates(): Promise<UpdateCheckResult> {
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) {
Expand Down Expand Up @@ -157,14 +150,8 @@ export class NsisUpdater extends EventEmitter {
return true
}

async loadUpdateConfig() {
try {
return createClient(safeLoad(await readFile(path.join((<any>global).__test_resourcesPath || (<any>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((<any>global).__test_resourcesPath || (<any>process).resourcesPath, "app-update.yml"), "utf-8")))
}
}

Expand Down
16 changes: 2 additions & 14 deletions test/src/nsisUpdaterTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down Expand Up @@ -134,24 +133,13 @@ test("test error", async () => {
const updater: NsisUpdater = new NsisUpdaterClass()

const actualEvents: Array<string> = []
const expectedEvents = ["checking-for-update", "error"]
const expectedEvents = ["checking-for-update", "error", "error"]
for (const eventName of expectedEvents) {
updater.addListener(eventName, () => {
actualEvents.push(eventName)
})
}

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)
})

0 comments on commit a457d0d

Please sign in to comment.