cherry-pick(#18822): chore(electron): filter test args out

This commit is contained in:
Pavel Feldman 2022-11-15 10:48:24 -08:00 committed by Pavel
parent e20be6c01e
commit 09c2d891ef
3 changed files with 13 additions and 2 deletions

View file

@ -130,7 +130,7 @@ export class Electron extends SdkObject {
controller.setLogName('browser'); controller.setLogName('browser');
return controller.run(async progress => { return controller.run(async progress => {
let app: ElectronApplication | undefined = undefined; let app: ElectronApplication | undefined = undefined;
const electronArguments = [require.resolve('./loader'), options.cwd || process.cwd(), ...args, '--inspect=0', '--remote-debugging-port=0']; const electronArguments = [require.resolve('./loader'), '--inspect=0', '--remote-debugging-port=0', options.cwd || process.cwd(), ...args];
if (os.platform() === 'linux') { if (os.platform() === 'linux') {
const runningAsRoot = process.geteuid && process.geteuid() === 0; const runningAsRoot = process.geteuid && process.geteuid() === 0;

View file

@ -18,7 +18,13 @@ const { app } = require('electron');
const path = require('path'); const path = require('path');
const { chromiumSwitches } = require('../chromium/chromiumSwitches'); const { chromiumSwitches } = require('../chromium/chromiumSwitches');
const appPath = path.resolve(process.argv[2], process.argv[3]); // Command line is like:
// [Electron, loader.js, --inspect=0, --remote-debugging-port=0, options.cwd, app.js, ...args]
const appPath = path.resolve(process.argv[4], process.argv[5]);
process.argv.splice(2, 4);
process.argv[1] = appPath;
// Now it is like
// [Electron, app.js, ...args]
for (const arg of chromiumSwitches) { for (const arg of chromiumSwitches) {
const match = arg.match(/--([^=]*)=?(.*)/)!; const match = arg.match(/--([^=]*)=?(.*)/)!;

View file

@ -38,6 +38,11 @@ test('should script application', async ({ electronApp }) => {
expect(appPath).toBe(path.resolve(__dirname)); expect(appPath).toBe(path.resolve(__dirname));
}); });
test('should preserve args', async ({ electronApp }) => {
const argv = await electronApp.evaluate(async ({ app }) => process.argv);
expect(argv.slice(1)).toEqual([expect.stringContaining('electron/electron-app.js')]);
});
test('should return windows', async ({ electronApp, newWindow }) => { test('should return windows', async ({ electronApp, newWindow }) => {
const window = await newWindow(); const window = await newWindow();
expect(electronApp.windows()).toEqual([window]); expect(electronApp.windows()).toEqual([window]);