Files
client/scripts/lib/electron-app.mjs
T

30 lines
1.4 KiB
JavaScript

// Deterministic Playwright launch of TeamsPeach for the smoke scripts.
//
// Dev tree: no executablePath, so Playwright starts its bundled Electron with its own `-r loader.js`, which
// holds the app's `ready` until Playwright has attached.
// Packaged build (--exe): Playwright cannot inject that loader, and when it attaches while the first page is
// committing its utility world is lost and `electron.launch` hangs. The app is therefore started with
// TEAMSPEACH_TEST_HOLD_WINDOW=1 and the window is created through the main-process hook only after attach.
import { _electron as electron } from 'playwright-core';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
export const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..');
/**
* @param {{ exe?: string, profile: string, args?: string[], env?: object, colorScheme?: null | 'light' | 'dark', timeout?: number }} o
*/
export async function launchApp({ exe, profile, args = [], env = {}, colorScheme = null, timeout }) {
const baseEnv = { ...process.env, TEAMSPEACH_PROFILE_DIR: profile, ...env };
if (!exe) return electron.launch({ args: [root, ...args], env: baseEnv, colorScheme, timeout });
const app = await electron.launch({
executablePath: path.resolve(exe),
args,
env: { ...baseEnv, TEAMSPEACH_TEST_HOLD_WINDOW: '1' },
colorScheme,
timeout,
});
await app.evaluate(() => globalThis.__teamspeachCreateWindow());
return app;
}