Skip to content

Commit

Permalink
cherry-pick(#18822): chore(electron): filter test args out
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman committed Nov 15, 2022
1 parent e20be6c commit 09c2d89
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/playwright-core/src/server/electron/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class Electron extends SdkObject {
controller.setLogName('browser');
return controller.run(async progress => {
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') {
const runningAsRoot = process.geteuid && process.geteuid() === 0;
Expand Down
8 changes: 7 additions & 1 deletion packages/playwright-core/src/server/electron/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ const { app } = require('electron');
const path = require('path');
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) {
const match = arg.match(/--([^=]*)=?(.*)/)!;
Expand Down
5 changes: 5 additions & 0 deletions tests/electron/electron-app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ test('should script application', async ({ electronApp }) => {
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 }) => {
const window = await newWindow();
expect(electronApp.windows()).toEqual([window]);
Expand Down

0 comments on commit 09c2d89

Please sign in to comment.