Skip to content

Commit

Permalink
Fix running playwright test with npm and electron.
Browse files Browse the repository at this point in the history
Fixes #14763

Contributed on behalf of STMicroelectronics

Signed-off-by: Thomas Mäder <[email protected]>
  • Loading branch information
tsmaeder committed Jan 23, 2025
1 parent ecf65d3 commit aafc482
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
19 changes: 8 additions & 11 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 @@ -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[], env: { [key: string]: 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,11 @@ namespace TheiaElectronAppLoader {
args.push(workspace.path);
}

return { executablePath: executablePath, args: args };
return {
args: args, env: {
'THEIA_NO_SPLASH': 'true'
}
};
}
return electronLaunchOptions;
}
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

0 comments on commit aafc482

Please sign in to comment.