Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix running playwright test with npm and electron. #14764

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions examples/playwright/src/theia-app-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
// *****************************************************************************

import { Page, PlaywrightWorkerArgs, _electron as electron } from '@playwright/test';
import * as path from 'path';
import * as fs from 'fs';
import { TheiaApp } from './theia-app';
import { TheiaWorkspace } from './theia-workspace';
import { OSUtil } from './util';

export interface TheiaAppFactory<T extends TheiaApp> {
new(page: Page, initialWorkspace: TheiaWorkspace, isElectron?: boolean): T;
Expand Down Expand Up @@ -104,7 +101,7 @@ namespace TheiaElectronAppLoader {
const appPath = electronConfig.electronAppPath!;
const pluginsPath = electronConfig.pluginsPath;
const launchOptions = electronConfig.launchOptions ?? {
additionalArgs: ['--no-cluster'],
additionalArgs: ['--no-sandbox', '--no-cluster'],
electronAppPath: appPath,
pluginsPath: pluginsPath
};
Expand All @@ -122,14 +119,10 @@ namespace TheiaElectronAppLoader {
export function toPlaywrightOptions(
electronLaunchOptions: { additionalArgs: string[], electronAppPath: string, pluginsPath?: string } | object,
workspace?: TheiaWorkspace
): { executablePath: string, args: string[] } | object {
): {
args: string[]
} | object {
if ('additionalArgs' in electronLaunchOptions && 'electronAppPath' in electronLaunchOptions) {
const executablePath = path.normalize(path.join(electronLaunchOptions.electronAppPath, 'node_modules/.bin/electron')) + (OSUtil.isWindows ? '.cmd' : '');
if (!fs.existsSync(executablePath)) {
const errorMsg = `executablePath: ${executablePath} does not exist`;
console.log(errorMsg);
throw new Error(errorMsg);
}
const args = [
electronLaunchOptions.electronAppPath,
...electronLaunchOptions.additionalArgs,
Expand All @@ -142,7 +135,9 @@ namespace TheiaElectronAppLoader {
args.push(workspace.path);
}

return { executablePath: executablePath, args: args };
return {
args: args
};
}
return electronLaunchOptions;
}
Expand All @@ -159,6 +154,7 @@ export namespace TheiaAppLoader {
// disable native elements and early window to avoid issues with the electron app
process.env.THEIA_ELECTRON_DISABLE_NATIVE_ELEMENTS = '1';
process.env.THEIA_ELECTRON_NO_EARLY_WINDOW = '1';
process.env.THEIA_NO_SPLASH = 'true';
return TheiaElectronAppLoader.load(args, initialWorkspace, factory);
}
const page = await args.browser.newPage();
Expand Down
8 changes: 5 additions & 3 deletions examples/playwright/src/theia-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ export class TheiaWorkspace {

get path(): string {
let workspacePath = this.workspacePath;
if (!OSUtil.osStartsWithFileSeparator(this.workspacePath)) {
workspacePath = `${OSUtil.fileSeparator}${workspacePath}`;
}

if (OSUtil.isWindows) {
// Drive letters in windows paths have to be lower case
workspacePath = workspacePath.replace(/.:/, matchedChar => matchedChar.toLowerCase());
} else {
if (!OSUtil.osStartsWithFileSeparator(this.workspacePath)) {
workspacePath = `${OSUtil.fileSeparator}${workspacePath}`;
}
}
return workspacePath;
}
Expand Down
20 changes: 10 additions & 10 deletions packages/core/src/electron-main/electron-main-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ export class ElectronMainApplication {
}

protected isShowSplashScreen(): boolean {
return typeof this.config.electron.splashScreenOptions === 'object' && !!this.config.electron.splashScreenOptions.content;
return !process.env.THEIA_NO_SPLASH && typeof this.config.electron.splashScreenOptions === 'object' && !!this.config.electron.splashScreenOptions.content;
}

protected getSplashScreenOptions(): ElectronFrontendApplicationConfig.SplashScreenOptions | undefined {
Expand Down Expand Up @@ -522,21 +522,21 @@ export class ElectronMainApplication {
}

protected async handleMainCommand(options: ElectronMainCommandOptions): Promise<void> {
if (options.secondInstance === false) {
await this.openWindowWithWorkspace(''); // restore previous workspace.
} else if (options.file === undefined) {
await this.openDefaultWindow();
} else {
let workspacePath: string | undefined;
let workspacePath: string | undefined;
if (options.file) {
try {
workspacePath = await fs.realpath(path.resolve(options.cwd, options.file));
} catch {
console.error(`Could not resolve the workspace path. "${options.file}" is not a valid 'file' option. Falling back to the default workspace location.`);
}
if (workspacePath === undefined) {
}
if (workspacePath !== undefined) {
await this.openWindowWithWorkspace(workspacePath);
} else {
if (options.secondInstance === false) {
await this.openWindowWithWorkspace(''); // restore previous workspace.
} else if (options.file === undefined) {
await this.openDefaultWindow();
} else {
await this.openWindowWithWorkspace(workspacePath);
}
}
}
Expand Down
Loading