Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: avoid DEP0190 warning in electron (#38280)
Yury Semikhatskya8b94062f4e6
diff --git a/packages/playwright-core/src/server/electron/electron.ts b/packages/playwright-core/src/server/electron/electron.tsindex aab06be4c8..8d54cbd39b 100644--- a/packages/playwright-core/src/server/electron/electron.ts+++ b/packages/playwright-core/src/server/electron/electron.ts@@ -195,10 +195,11 @@ export class Electron extends SdkObject {// On Windows in order to run .cmd files, shell: true is required.// https://github.com/nodejs/node/issues/52554shell = true;- // On Windows, we need to quote the executable path due to shell: true.- command = `"${command}"`;- // On Windows, we need to quote the arguments due to shell: true.- electronArguments = electronArguments.map(arg => `"${arg}"`);+ // On Windows, we need to quote the executable path and arguments due to shell: true.+ // We allso pass the arguments as a single string due to DEP0190,+ // see https://github.com/microsoft/playwright/issues/38278.+ command = [command, ...electronArguments].map(arg => `"${escapeWinCmdArg(arg)}"`).join(' ');+ electronArguments = [];}// When debugging Playwright test that runs Electron, NODE_OPTIONS@@ -315,3 +316,7 @@ async function waitForLine(progress: Progress, process: childProcess.ChildProceseventsHelper.removeEventListeners(listeners);}}++function escapeWinCmdArg(str: string): string {+ return str.replace(/"/g, '\\"').replace(/%([^%].)/g, '%^$1');+}diff --git a/tests/electron/electron-app.spec.ts b/tests/electron/electron-app.spec.tsindex c725752e37..f1d8e351f9 100644--- a/tests/electron/electron-app.spec.ts+++ b/tests/electron/electron-app.spec.ts@@ -130,10 +130,10 @@ test('should script application', async ({ electronApp }) => {});test('should preserve args', async ({ launchElectronApp, isMac }) => {- const electronApp = await launchElectronApp('electron-app-args.js', ['foo', 'bar']);+ const electronApp = await launchElectronApp('electron-app-args.js', ['foo', 'bar', '%PATH%', '& <>^|\\"']);const argv = await electronApp.evaluate(async () => globalThis.argv);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']);+ expect(argv).toEqual([expect.stringContaining(electronPath), expect.stringContaining(path.join('electron', 'electron-app-args.js')), 'foo', 'bar', '%^PATH%', '& <>^|\\"']);});test('should return windows', async ({ electronApp, newWindow }) => {diff --git a/tests/electron/globalSetup.ts b/tests/electron/globalSetup.tsindex 3b4021b8af..9edeef68c5 100644--- a/tests/electron/globalSetup.ts+++ b/tests/electron/globalSetup.ts@@ -18,7 +18,7 @@ import assert from 'assert';import { spawnAsync } from '../../packages/playwright-core/lib/server/utils/spawnAsync';export default async () => {- const result = await spawnAsync('npx', ['electron', require.resolve('./electron-print-chromium-version.js'), '--no-sandbox'], {+ const result = await spawnAsync(['npx', 'electron', `"${require.resolve('./electron-print-chromium-version.js')}"`, '--no-sandbox'].join(' '), [], {shell: true,});const chromiumVersion = result.stdout.trim();