Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

desktop: add more tests for auto updater

Abdullah Atta1adddbdb4cc8
diff --git a/apps/desktop/__tests__/auto-updates.test.ts b/apps/desktop/__tests__/auto-updates.test.ts
index 3a3a6ef6f..6387fdd8c 100644
--- a/apps/desktop/__tests__/auto-updates.test.ts
+++ b/apps/desktop/__tests__/auto-updates.test.ts
@@ -19,8 +19,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import { test } from "vitest";
import { harness } from "./utils.js";
-import assert from "assert";
import { writeFile } from "fs/promises";
+import { Page } from "playwright";
+import { gt, lt } from "semver";
test("update starts downloading if version is outdated", async (t) => {
await harness(
@@ -28,30 +29,15 @@ test("update starts downloading if version is outdated", async (t) => {
async ({ page }) => {
await page.waitForSelector("#authForm");
- assert.ok(
+ t.expect(
await page.getByRole("button", { name: "Create account" }).isVisible()
- );
+ ).toBe(true);
await page
.getByRole("button", { name: "Skip & go directly to the app" })
.click();
- await page
- .waitForSelector(".ReactModal__Content", {
- timeout: 1000
- })
- .catch(() => {})
- .then(async () => {
- const positiveButton = page.locator(
- "button[data-role='positive-button']"
- );
- const negativeButton = page.locator(
- "button[data-role='negative-button']"
- );
- if (await positiveButton.isVisible()) await positiveButton.click();
- else if (await negativeButton.isVisible())
- await negativeButton.click();
- });
+ await skipDialog(page);
await page.waitForSelector(".ProseMirror");
@@ -82,30 +68,15 @@ test("update is only shown if version is outdated and auto updates are disabled"
await page.waitForSelector("#authForm");
- assert.ok(
+ t.expect(
await page.getByRole("button", { name: "Create account" }).isVisible()
- );
+ ).toBe(true);
await page
.getByRole("button", { name: "Skip & go directly to the app" })
.click();
- await page
- .waitForSelector(".ReactModal__Content", {
- timeout: 1000
- })
- .catch(() => {})
- .then(async () => {
- const positiveButton = page.locator(
- "button[data-role='positive-button']"
- );
- const negativeButton = page.locator(
- "button[data-role='negative-button']"
- );
- if (await positiveButton.isVisible()) await positiveButton.click();
- else if (await negativeButton.isVisible())
- await negativeButton.click();
- });
+ await skipDialog(page);
await page.waitForSelector(".ProseMirror");
@@ -117,3 +88,159 @@ test("update is only shown if version is outdated and auto updates are disabled"
{ version: "3.0.0" }
);
});
+
+test("update to stable if it is newer", async (t) => {
+ await harness(
+ t,
+ async (ctx) => {
+ await ctx.app.close();
+ await writeFile(
+ ctx.configPath,
+ JSON.stringify({
+ automaticUpdates: false,
+ releaseTrack: "beta"
+ })
+ );
+
+ await ctx.relaunch();
+
+ const { page } = ctx;
+
+ await page.waitForSelector("#authForm");
+
+ t.expect(
+ await page.getByRole("button", { name: "Create account" }).isVisible()
+ ).toBe(true);
+
+ await page
+ .getByRole("button", { name: "Skip & go directly to the app" })
+ .click();
+
+ await skipDialog(page);
+
+ await page.waitForSelector(".ProseMirror");
+
+ const updateButton = page
+ .locator(".theme-scope-statusBar")
+ .getByRole("button", { name: /available/i });
+ await updateButton.waitFor({ state: "visible" });
+ const content = await updateButton.textContent();
+ const version = content?.split(" ")?.[0] || "";
+ t.expect(gt(version, "3.0.0-beta.0")).toBe(true);
+ },
+ { version: "3.0.0-beta.0" }
+ );
+});
+
+test("update is not available if it latest stable version is older", async (t) => {
+ await harness(
+ t,
+ async (ctx) => {
+ await ctx.app.close();
+ await writeFile(
+ ctx.configPath,
+ JSON.stringify({
+ automaticUpdates: false,
+ releaseTrack: "beta"
+ })
+ );
+
+ await ctx.relaunch();
+
+ const { page } = ctx;
+
+ await page.waitForSelector("#authForm");
+
+ t.expect(
+ await page.getByRole("button", { name: "Create account" }).isVisible()
+ ).toBe(true);
+
+ await page
+ .getByRole("button", { name: "Skip & go directly to the app" })
+ .click();
+
+ await skipDialog(page);
+
+ await page.waitForSelector(".ProseMirror");
+
+ await page
+ .locator(".theme-scope-statusBar")
+ .getByRole("button", { name: /checking for updates/i })
+ .waitFor({ state: "hidden" });
+
+ t.expect(
+ await page
+ .locator(".theme-scope-statusBar")
+ .getByRole("button", { name: /available/i })
+ .isHidden()
+ ).toBe(true);
+ },
+ { version: "99.0.0-beta.0" }
+ );
+});
+
+test("downgrade to stable on switching to stable release track", async (t) => {
+ await harness(
+ t,
+ async (ctx) => {
+ await ctx.app.close();
+ await writeFile(
+ ctx.configPath,
+ JSON.stringify({
+ automaticUpdates: false,
+ releaseTrack: "stable"
+ })
+ );
+
+ await ctx.relaunch();
+
+ const { page } = ctx;
+
+ await page.waitForSelector("#authForm");
+
+ t.expect(
+ await page.getByRole("button", { name: "Create account" }).isVisible()
+ ).toBe(true);
+
+ await page
+ .getByRole("button", { name: "Skip & go directly to the app" })
+ .click();
+
+ await skipDialog(page);
+
+ await page.waitForSelector(".ProseMirror");
+
+ await page
+ .locator(".theme-scope-statusBar")
+ .getByRole("button", { name: /checking for updates/i })
+ .waitFor({ state: "hidden" });
+
+ const updateButton = page
+ .locator(".theme-scope-statusBar")
+ .getByRole("button", { name: /available/i });
+ await updateButton.waitFor({ state: "visible" });
+ const content = await updateButton.textContent();
+ const version = content?.split(" ")?.[0] || "";
+ t.expect(lt(version, "99.0.0-beta.0")).toBe(true);
+ },
+ { version: "99.0.0-beta.0" }
+ );
+});
+
+async function skipDialog(page: Page) {
+ await page
+ .waitForSelector(".ReactModal__Content", {
+ timeout: 1000
+ })
+ .catch(() => {})
+ .then(async () => {
+ const positiveButton = page.locator(
+ "button[data-role='positive-button']"
+ );
+ const negativeButton = page.locator(
+ "button[data-role='negative-button']"
+ );
+ if (await positiveButton.isVisible()) await positiveButton.click();
+ else if (await negativeButton.isVisible()) await negativeButton.click();
+ });
+}
diff --git a/apps/desktop/package.json b/apps/desktop/package.json
index 8bfd95acf..b689c26af 100644
--- a/apps/desktop/package.json
+++ b/apps/desktop/package.json
@@ -66,7 +66,7 @@
"bundle": "esbuild electron=./src/main.ts ./src/preload.ts --external:electron --external:fsevents --external:better-sqlite3-multiple-ciphers --external:sodium-native --bundle --outdir=./build --platform=node --tsconfig=tsconfig.json --define:MAC_APP_STORE=false --define:RELEASE=true",
"bundle:mas": "esbuild electron=./src/main.ts ./src/preload.ts --minify --external:electron --external:fsevents --bundle --outdir=./build --platform=node --tsconfig=tsconfig.json --define:MAC_APP_STORE=true --define:RELEASE=true",
"postinstall": "patch-package",
- "test": "node --test --test-timeout 30000 --test-force-exit --test-concurrency=8"
+ "test": "vitest run"
},
"author": {
"name": "Streetwriters (Private) Limited",