Skip to content

Commit 3867d55

Browse files
cherry-pick(#30820): fix(electron): allow launching with spaces in path (#30830)
This PR cherry-picks the following commits: - 90765a2 Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 01bf93c commit 3867d55

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

packages/playwright-core/src/server/electron/electron.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export class Electron extends SdkObject {
161161
return controller.run(async progress => {
162162
let app: ElectronApplication | undefined = undefined;
163163
// --remote-debugging-port=0 must be the last playwright's argument, loader.ts relies on it.
164-
const electronArguments = ['--inspect=0', '--remote-debugging-port=0', ...args];
164+
let electronArguments = ['--inspect=0', '--remote-debugging-port=0', ...args];
165165

166166
if (os.platform() === 'linux') {
167167
const runningAsRoot = process.geteuid && process.geteuid() === 0;
@@ -195,6 +195,16 @@ export class Electron extends SdkObject {
195195
// Packaged apps might have their own command line handling.
196196
electronArguments.unshift('-r', require.resolve('./loader'));
197197
}
198+
let shell = false;
199+
if (process.platform === 'win32') {
200+
// On Windows in order to run .cmd files, shell: true is required.
201+
// https://github.com/nodejs/node/issues/52554
202+
shell = true;
203+
// On Windows, we need to quote the executable path due to shell: true.
204+
command = `"${command}"`;
205+
// On Windows, we need to quote the arguments due to shell: true.
206+
electronArguments = electronArguments.map(arg => `"${arg}"`);
207+
}
198208

199209
// When debugging Playwright test that runs Electron, NODE_OPTIONS
200210
// will make the debugger attach to Electron's Node. But Playwright
@@ -208,9 +218,7 @@ export class Electron extends SdkObject {
208218
progress.log(message);
209219
browserLogsCollector.log(message);
210220
},
211-
// On Windows in order to run .cmd files, shell: true is required.
212-
// https://github.com/nodejs/node/issues/52554
213-
shell: process.platform === 'win32',
221+
shell,
214222
stdio: 'pipe',
215223
cwd: options.cwd,
216224
tempDirectories: [artifactsDir],

tests/installation/playwright-electron-should-work.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616
import { test } from './npmTest';
17+
import fs from 'fs';
18+
import path from 'path';
1719

1820
test('electron should work', async ({ exec, tsc, writeFiles }) => {
1921
await exec('npm i playwright [email protected]');
@@ -24,3 +26,16 @@ test('electron should work', async ({ exec, tsc, writeFiles }) => {
2426
});
2527
await tsc('test.ts');
2628
});
29+
30+
test('electron should work with special characters in path', async ({ exec, tmpWorkspace }) => {
31+
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/30755' });
32+
const folderName = path.join(tmpWorkspace, '!@#$% тест with spaces and 😊');
33+
34+
await exec('npm i playwright [email protected]');
35+
await fs.promises.mkdir(folderName);
36+
for (const file of ['electron-app.js', 'sanity-electron.js'])
37+
await fs.promises.copyFile(path.join(tmpWorkspace, file), path.join(folderName, file));
38+
await exec('node sanity-electron.js', {
39+
cwd: path.join(folderName)
40+
});
41+
});

0 commit comments

Comments
 (0)