2024-01-11 19:49:20 +01:00
|
|
|
/*
|
2024-09-06 18:56:18 +02:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2024-01-11 19:49:20 +01:00
|
|
|
Copyright 2023 The Matrix.org Foundation C.I.C.
|
|
|
|
|
2024-09-06 18:56:18 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2024-01-11 19:49:20 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
import { _electron as electron, test as base, expect as baseExpect, type ElectronApplication } from "@playwright/test";
|
|
|
|
import fs from "node:fs/promises";
|
2024-10-30 19:06:03 +01:00
|
|
|
import path, { dirname } from "node:path";
|
2024-01-11 19:49:20 +01:00
|
|
|
import os from "node:os";
|
2024-10-30 19:06:03 +01:00
|
|
|
import { fileURLToPath } from "node:url";
|
2024-01-11 19:49:20 +01:00
|
|
|
|
2024-10-17 14:26:35 +02:00
|
|
|
interface Fixtures {
|
|
|
|
app: ElectronApplication;
|
|
|
|
tmpDir: string;
|
|
|
|
extraEnv: Record<string, string>;
|
|
|
|
extraArgs: string[];
|
|
|
|
}
|
|
|
|
|
2024-10-30 19:06:03 +01:00
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
|
|
2024-10-17 14:26:35 +02:00
|
|
|
export const test = base.extend<Fixtures>({
|
|
|
|
extraEnv: {},
|
|
|
|
extraArgs: [],
|
2024-01-11 19:49:20 +01:00
|
|
|
// eslint-disable-next-line no-empty-pattern
|
|
|
|
tmpDir: async ({}, use) => {
|
|
|
|
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "element-desktop-tests-"));
|
|
|
|
console.log("Using temp profile directory: ", tmpDir);
|
|
|
|
await use(tmpDir);
|
|
|
|
await fs.rm(tmpDir, { recursive: true });
|
|
|
|
},
|
2024-10-17 14:26:35 +02:00
|
|
|
app: async ({ tmpDir, extraEnv, extraArgs }, use) => {
|
2024-01-11 19:49:20 +01:00
|
|
|
const args = ["--profile-dir", tmpDir];
|
|
|
|
|
|
|
|
const executablePath = process.env["ELEMENT_DESKTOP_EXECUTABLE"];
|
|
|
|
if (!executablePath) {
|
|
|
|
// Unpackaged mode testing
|
2024-03-12 19:31:13 +01:00
|
|
|
args.unshift(path.join(__dirname, "..", "lib", "electron-main.js"));
|
2024-01-11 19:49:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const app = await electron.launch({
|
2024-10-17 14:26:35 +02:00
|
|
|
env: {
|
|
|
|
...process.env,
|
|
|
|
...extraEnv,
|
|
|
|
},
|
2024-01-11 19:49:20 +01:00
|
|
|
executablePath,
|
2024-10-17 14:26:35 +02:00
|
|
|
args: [...args, ...extraArgs],
|
2024-01-11 19:49:20 +01:00
|
|
|
});
|
|
|
|
|
2024-03-12 19:31:13 +01:00
|
|
|
app.process().stdout.pipe(process.stdout);
|
|
|
|
app.process().stderr.pipe(process.stderr);
|
|
|
|
|
2024-01-11 19:49:20 +01:00
|
|
|
await app.firstWindow();
|
|
|
|
await use(app);
|
|
|
|
},
|
|
|
|
page: async ({ app }, use) => {
|
|
|
|
const window = await app.firstWindow();
|
|
|
|
await use(window);
|
|
|
|
await app.close().catch((e) => {
|
|
|
|
console.error(e);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export const expect = baseExpect;
|