From 8b2c78c4a445b04079307b2a21bed481de439484 Mon Sep 17 00:00:00 2001 From: Asher Date: Mon, 3 May 2021 17:39:59 -0500 Subject: [PATCH] Re-enable update tests --- src/common/util.ts | 3 +++ test/unit/update.test.ts | 39 +++++++++++++++++++++++---------------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/common/util.ts b/src/common/util.ts index 122cd176..4e4f23cf 100644 --- a/src/common/util.ts +++ b/src/common/util.ts @@ -77,6 +77,9 @@ export const getOptions = (): T => { options = {} as T } + // You can also pass options in stringified form to the options query + // variable. Options provided here will override the ones in the options + // element. const params = new URLSearchParams(location.search) const queryOpts = params.get("options") if (queryOpts) { diff --git a/test/unit/update.test.ts b/test/unit/update.test.ts index 39437120..e76c87d3 100644 --- a/test/unit/update.test.ts +++ b/test/unit/update.test.ts @@ -5,7 +5,7 @@ import { tmpdir } from "../../src/node/constants" import { SettingsProvider, UpdateSettings } from "../../src/node/settings" import { LatestResponse, UpdateProvider } from "../../src/node/update" -describe.skip("update", () => { +describe("update", () => { let version = "1.0.0" let spy: string[] = [] const server = http.createServer((request: http.IncomingMessage, response: http.ServerResponse) => { @@ -75,7 +75,7 @@ describe.skip("update", () => { await expect(settings.read()).resolves.toEqual({ update }) expect(isNaN(update.checked)).toEqual(false) expect(update.checked < Date.now() && update.checked >= now).toEqual(true) - expect(update.version).toBe("2.1.0") + expect(update.version).toStrictEqual("2.1.0") expect(spy).toEqual(["/latest"]) }) @@ -87,9 +87,9 @@ describe.skip("update", () => { const update = await p.getUpdate() await expect(settings.read()).resolves.toEqual({ update }) - expect(isNaN(update.checked)).toBe(false) + expect(isNaN(update.checked)).toStrictEqual(false) expect(update.checked < now).toBe(true) - expect(update.version).toBe("2.1.0") + expect(update.version).toStrictEqual("2.1.0") expect(spy).toEqual([]) }) @@ -101,10 +101,10 @@ describe.skip("update", () => { const update = await p.getUpdate(true) await expect(settings.read()).resolves.toEqual({ update }) - expect(isNaN(update.checked)).toBe(false) - expect(update.checked < Date.now() && update.checked >= now).toBe(true) - expect(update.version).toBe("4.1.1") - expect(spy).toBe(["/latest"]) + expect(isNaN(update.checked)).toStrictEqual(false) + expect(update.checked < Date.now() && update.checked >= now).toStrictEqual(true) + expect(update.version).toStrictEqual("4.1.1") + expect(spy).toStrictEqual(["/latest"]) }) it("should get latest after interval passes", async () => { @@ -121,8 +121,8 @@ describe.skip("update", () => { await settings.write({ update: { checked, version } }) const update = await p.getUpdate() - expect(update.checked).not.toBe(checked) - expect(spy).toBe(["/latest"]) + expect(update.checked).not.toStrictEqual(checked) + expect(spy).toStrictEqual(["/latest"]) }) it("should check if it's the current version", async () => { @@ -130,24 +130,31 @@ describe.skip("update", () => { const p = provider() let update = await p.getUpdate(true) - expect(p.isLatestVersion(update)).toBe(false) + expect(p.isLatestVersion(update)).toStrictEqual(false) version = "0.0.0" update = await p.getUpdate(true) - expect(p.isLatestVersion(update)).toBe(true) + expect(p.isLatestVersion(update)).toStrictEqual(true) // Old version format; make sure it doesn't report as being later. version = "999999.9999-invalid999.99.9" update = await p.getUpdate(true) - expect(p.isLatestVersion(update)).toBe(true) + expect(p.isLatestVersion(update)).toStrictEqual(true) }) it("should not reject if unable to fetch", async () => { - expect.assertions(2) let provider = new UpdateProvider("invalid", settings) - await expect(() => provider.getUpdate(true)).resolves.toBe(undefined) + let now = Date.now() + let update = await provider.getUpdate(true) + expect(isNaN(update.checked)).toStrictEqual(false) + expect(update.checked < Date.now() && update.checked >= now).toEqual(true) + expect(update.version).toStrictEqual("unknown") provider = new UpdateProvider("http://probably.invalid.dev.localhost/latest", settings) - await expect(() => provider.getUpdate(true)).resolves.toBe(undefined) + now = Date.now() + update = await provider.getUpdate(true) + expect(isNaN(update.checked)).toStrictEqual(false) + expect(update.checked < Date.now() && update.checked >= now).toEqual(true) + expect(update.version).toStrictEqual("unknown") }) })