Skip to content

Commit 8ebc485

Browse files
authored
Fix running playwright test with npm and electron. (#14764)
Fixes #14763 Contributed on behalf of STMicroelectronics
1 parent 55ec098 commit 8ebc485

File tree

3 files changed

+23
-25
lines changed

3 files changed

+23
-25
lines changed

examples/playwright/src/theia-app-loader.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@
1515
// *****************************************************************************
1616

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

2421
export interface TheiaAppFactory<T extends TheiaApp> {
2522
new(page: Page, initialWorkspace: TheiaWorkspace, isElectron?: boolean): T;
@@ -104,7 +101,7 @@ namespace TheiaElectronAppLoader {
104101
const appPath = electronConfig.electronAppPath!;
105102
const pluginsPath = electronConfig.pluginsPath;
106103
const launchOptions = electronConfig.launchOptions ?? {
107-
additionalArgs: ['--no-cluster'],
104+
additionalArgs: ['--no-sandbox', '--no-cluster'],
108105
electronAppPath: appPath,
109106
pluginsPath: pluginsPath
110107
};
@@ -122,14 +119,10 @@ namespace TheiaElectronAppLoader {
122119
export function toPlaywrightOptions(
123120
electronLaunchOptions: { additionalArgs: string[], electronAppPath: string, pluginsPath?: string } | object,
124121
workspace?: TheiaWorkspace
125-
): { executablePath: string, args: string[] } | object {
122+
): {
123+
args: string[]
124+
} | object {
126125
if ('additionalArgs' in electronLaunchOptions && 'electronAppPath' in electronLaunchOptions) {
127-
const executablePath = path.normalize(path.join(electronLaunchOptions.electronAppPath, 'node_modules/.bin/electron')) + (OSUtil.isWindows ? '.cmd' : '');
128-
if (!fs.existsSync(executablePath)) {
129-
const errorMsg = `executablePath: ${executablePath} does not exist`;
130-
console.log(errorMsg);
131-
throw new Error(errorMsg);
132-
}
133126
const args = [
134127
electronLaunchOptions.electronAppPath,
135128
...electronLaunchOptions.additionalArgs,
@@ -142,7 +135,9 @@ namespace TheiaElectronAppLoader {
142135
args.push(workspace.path);
143136
}
144137

145-
return { executablePath: executablePath, args: args };
138+
return {
139+
args: args
140+
};
146141
}
147142
return electronLaunchOptions;
148143
}
@@ -159,6 +154,7 @@ export namespace TheiaAppLoader {
159154
// disable native elements and early window to avoid issues with the electron app
160155
process.env.THEIA_ELECTRON_DISABLE_NATIVE_ELEMENTS = '1';
161156
process.env.THEIA_ELECTRON_NO_EARLY_WINDOW = '1';
157+
process.env.THEIA_NO_SPLASH = 'true';
162158
return TheiaElectronAppLoader.load(args, initialWorkspace, factory);
163159
}
164160
const page = await args.browser.newPage();

examples/playwright/src/theia-workspace.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ export class TheiaWorkspace {
4747

4848
get path(): string {
4949
let workspacePath = this.workspacePath;
50-
if (!OSUtil.osStartsWithFileSeparator(this.workspacePath)) {
51-
workspacePath = `${OSUtil.fileSeparator}${workspacePath}`;
52-
}
50+
5351
if (OSUtil.isWindows) {
5452
// Drive letters in windows paths have to be lower case
5553
workspacePath = workspacePath.replace(/.:/, matchedChar => matchedChar.toLowerCase());
54+
} else {
55+
if (!OSUtil.osStartsWithFileSeparator(this.workspacePath)) {
56+
workspacePath = `${OSUtil.fileSeparator}${workspacePath}`;
57+
}
5658
}
5759
return workspacePath;
5860
}

packages/core/src/electron-main/electron-main-application.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ export class ElectronMainApplication {
396396
}
397397

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

402402
protected getSplashScreenOptions(): ElectronFrontendApplicationConfig.SplashScreenOptions | undefined {
@@ -522,21 +522,21 @@ export class ElectronMainApplication {
522522
}
523523

524524
protected async handleMainCommand(options: ElectronMainCommandOptions): Promise<void> {
525-
if (options.secondInstance === false) {
526-
await this.openWindowWithWorkspace(''); // restore previous workspace.
527-
} else if (options.file === undefined) {
528-
await this.openDefaultWindow();
529-
} else {
530-
let workspacePath: string | undefined;
525+
let workspacePath: string | undefined;
526+
if (options.file) {
531527
try {
532528
workspacePath = await fs.realpath(path.resolve(options.cwd, options.file));
533529
} catch {
534530
console.error(`Could not resolve the workspace path. "${options.file}" is not a valid 'file' option. Falling back to the default workspace location.`);
535531
}
536-
if (workspacePath === undefined) {
532+
}
533+
if (workspacePath !== undefined) {
534+
await this.openWindowWithWorkspace(workspacePath);
535+
} else {
536+
if (options.secondInstance === false) {
537+
await this.openWindowWithWorkspace(''); // restore previous workspace.
538+
} else if (options.file === undefined) {
537539
await this.openDefaultWindow();
538-
} else {
539-
await this.openWindowWithWorkspace(workspacePath);
540540
}
541541
}
542542
}

0 commit comments

Comments
 (0)