fix(electron): do not use loader for packaged apps (#21577)

References #21387, #21512.
This commit is contained in:
Dmitry Gozman 2023-03-13 12:52:52 -07:00 committed by GitHub
parent 1d870ac407
commit 8e7ec88462
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 6 deletions

View File

@ -130,7 +130,7 @@ export class Electron extends SdkObject {
controller.setLogName('browser');
return controller.run(async progress => {
let app: ElectronApplication | undefined = undefined;
const electronArguments = ['-r', require.resolve('./loader'), '--inspect=0', '--remote-debugging-port=0', ...args];
const electronArguments = ['--inspect=0', '--remote-debugging-port=0', ...args];
if (os.platform() === 'linux') {
const runningAsRoot = process.geteuid && process.geteuid() === 0;
@ -160,6 +160,9 @@ export class Electron extends SdkObject {
}
throw error;
}
// Only use our own loader for non-packaged apps.
// Packaged apps might have their own command line handling.
electronArguments.unshift('-r', require.resolve('./loader'));
}
// When debugging Playwright test that runs Electron, NODE_OPTIONS

View File

@ -49,10 +49,10 @@ test('should script application', async ({ electronApp }) => {
});
test('should preserve args', async ({ launchElectronApp, isMac }) => {
test.fixme(isMac, 'https://github.com/microsoft/playwright/issues/21512');
const electronApp = await launchElectronApp('electron-app-args.js', ['foo', 'bar']);
const argv = await electronApp.evaluate(async () => globalThis.argv);
expect(argv).toEqual([expect.stringContaining(path.join('dist', 'electron')), expect.stringContaining(path.join('electron', 'electron-app-args.js')), 'foo', 'bar']);
const electronPath = isMac ? path.join('dist', 'Electron.app') : path.join('dist', 'electron');
expect(argv).toEqual([expect.stringContaining(electronPath), expect.stringContaining(path.join('electron', 'electron-app-args.js')), 'foo', 'bar']);
});
test('should return windows', async ({ electronApp, newWindow }) => {

View File

@ -16,7 +16,7 @@
import { baseTest } from '../config/baseTest';
import * as path from 'path';
import type { ElectronApplication, Page } from '@playwright/test';
import type { ElectronApplication, Page, Electron } from '@playwright/test';
import type { PageTestFixtures, PageWorkerFixtures } from '../page/pageTestApi';
import type { TraceViewerFixtures } from '../config/traceViewerFixtures';
import { traceViewerFixtures } from '../config/traceViewerFixtures';
@ -26,7 +26,7 @@ import { assert } from '../../packages/playwright-core/lib/utils/debug';
type ElectronTestFixtures = PageTestFixtures & {
electronApp: ElectronApplication;
launchElectronApp: (appFile: string, args?: string[], options?: any) => Promise<ElectronApplication>;
launchElectronApp: (appFile: string, args?: string[], options?: Parameters<Electron['launch']>[0]) => Promise<ElectronApplication>;
newWindow: () => Promise<Page>;
};
@ -45,7 +45,7 @@ export const electronTest = baseTest.extend<TraceViewerFixtures>(traceViewerFixt
// This env prevents 'Electron Security Policy' console message.
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';
const apps: ElectronApplication[] = [];
await use(async (appFile: string, args: string[] = [], options?: any[]) => {
await use(async (appFile: string, args: string[] = [], options?: Parameters<Electron['launch']>[0]) => {
const app = await playwright._electron.launch({ ...options, args: [path.join(__dirname, appFile), ...args] });
apps.push(app);
return app;