From 8c51bed2d0be5732d8a8ce4f4cd98ff4e3b5ec2a Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 17 Mar 2025 10:47:25 +0000 Subject: [PATCH] Add test Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- playwright/e2e/launch/launch.spec.ts | 10 +++++++ playwright/element-desktop-test.ts | 41 ++++++++++++++++++++++++++-- src/electron-main.ts | 1 + 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/playwright/e2e/launch/launch.spec.ts b/playwright/e2e/launch/launch.spec.ts index 3b231ff2..fec9a8c8 100644 --- a/playwright/e2e/launch/launch.spec.ts +++ b/playwright/e2e/launch/launch.spec.ts @@ -55,4 +55,14 @@ test.describe("App launch", () => { }), ).resolves.not.toBeNull(); }); + + test.describe("--no-update", () => { + test.use({ + extraArgs: ["--no-update"], + }); + + test("should respect option", async ({ page, stdout }) => { + expect(stdout.data.toString()).toContain("Auto update disabled via command line flag"); + }); + }); }); diff --git a/playwright/element-desktop-test.ts b/playwright/element-desktop-test.ts index f3bf535b..3d8d4f54 100644 --- a/playwright/element-desktop-test.ts +++ b/playwright/element-desktop-test.ts @@ -11,12 +11,37 @@ import fs from "node:fs/promises"; import path, { dirname } from "node:path"; import os from "node:os"; import { fileURLToPath } from "node:url"; +import { PassThrough } from "node:stream"; + +/** + * A PassThrough stream that captures all data written to it. + */ +class CapturedPassThrough extends PassThrough { + private _chunks = []; + + public constructor() { + super(); + super.on("data", this.onData); + } + + private onData = (chunk): void => { + this._chunks.push(chunk); + }; + + public get data(): Buffer { + return Buffer.concat(this._chunks); + } +} interface Fixtures { app: ElectronApplication; tmpDir: string; extraEnv: Record; extraArgs: string[]; + + // Utilities to capture stdout and stderr for tests to make assertions against + stdout: CapturedPassThrough; + stderr: CapturedPassThrough; } const __dirname = dirname(fileURLToPath(import.meta.url)); @@ -24,6 +49,16 @@ const __dirname = dirname(fileURLToPath(import.meta.url)); export const test = base.extend({ extraEnv: {}, extraArgs: [], + + // eslint-disable-next-line no-empty-pattern + stdout: async ({}, use) => { + await use(new CapturedPassThrough()); + }, + // eslint-disable-next-line no-empty-pattern + stderr: async ({}, use) => { + await use(new CapturedPassThrough()); + }, + // eslint-disable-next-line no-empty-pattern tmpDir: async ({}, use) => { const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "element-desktop-tests-")); @@ -31,7 +66,7 @@ export const test = base.extend({ await use(tmpDir); await fs.rm(tmpDir, { recursive: true }); }, - app: async ({ tmpDir, extraEnv, extraArgs }, use) => { + app: async ({ tmpDir, extraEnv, extraArgs, stdout, stderr }, use) => { const args = ["--profile-dir", tmpDir]; const executablePath = process.env["ELEMENT_DESKTOP_EXECUTABLE"]; @@ -49,8 +84,8 @@ export const test = base.extend({ args: [...args, ...extraArgs], }); - app.process().stdout.pipe(process.stdout); - app.process().stderr.pipe(process.stderr); + app.process().stdout.pipe(stdout).pipe(process.stdout); + app.process().stderr.pipe(stderr).pipe(process.stderr); await app.firstWindow(); diff --git a/src/electron-main.ts b/src/electron-main.ts index 913f253f..6b243f75 100644 --- a/src/electron-main.ts +++ b/src/electron-main.ts @@ -436,6 +436,7 @@ app.on("ready", async () => { }); }); + // Minimist parses `--no-`-prefixed arguments as booleans with value `false` rather than verbatim. if (argv["update"] === false) { console.log("Auto update disabled via command line flag"); } else if (global.vectorConfig["update_base_url"]) {