Skip to content

Commit

Permalink
fix(electron): allow launching with spaces in path
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed May 15, 2024
1 parent fb319e6 commit 7dfa031
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
20 changes: 17 additions & 3 deletions packages/playwright-core/src/server/electron/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,22 @@ export class Electron extends SdkObject {
// Packaged apps might have their own command line handling.
electronArguments.unshift('-r', require.resolve('./loader'));
}
let shell = false;
if (process.platform === 'win32') {
// On Windows in order to run .cmd files, shell: true is required.
// https://github.com/nodejs/node/issues/52554
shell = true;
// On Windows, we need to quote the executable path if it has spaces.
if (command.includes(' ')) {

Check failure on line 204 in packages/playwright-core/src/server/electron/electron.ts

View workflow job for this annotation

GitHub Actions / docs & lint

Unnecessary { after 'if' condition
command = `"${command}"`;
}
// On Windows, we need to quote the arguments if they have spaces.
electronArguments.forEach((arg, index) => {
if (arg.includes(' ')) {

Check failure on line 209 in packages/playwright-core/src/server/electron/electron.ts

View workflow job for this annotation

GitHub Actions / docs & lint

Unnecessary { after 'if' condition
electronArguments[index] = `"${arg}"`;
}
});
}

// When debugging Playwright test that runs Electron, NODE_OPTIONS
// will make the debugger attach to Electron's Node. But Playwright
Expand All @@ -208,9 +224,7 @@ export class Electron extends SdkObject {
progress.log(message);
browserLogsCollector.log(message);
},
// On Windows in order to run .cmd files, shell: true is required.
// https://github.com/nodejs/node/issues/52554
shell: process.platform === 'win32',
shell,
stdio: 'pipe',
cwd: options.cwd,
tempDirectories: [artifactsDir],
Expand Down
15 changes: 15 additions & 0 deletions tests/installation/playwright-electron-should-work.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/
import { test } from './npmTest';
import fs from 'fs';
import path from "path"

Check failure on line 18 in tests/installation/playwright-electron-should-work.spec.ts

View workflow job for this annotation

GitHub Actions / docs & lint

Strings must use singlequote

Check failure on line 18 in tests/installation/playwright-electron-should-work.spec.ts

View workflow job for this annotation

GitHub Actions / docs & lint

Missing semicolon

test('electron should work', async ({ exec, tsc, writeFiles }) => {
await exec('npm i playwright [email protected]');
Expand All @@ -24,3 +26,16 @@ test('electron should work', async ({ exec, tsc, writeFiles }) => {
});
await tsc('test.ts');
});

test('electron should work with special characters in path', async ({ exec, tmpWorkspace }) => {
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/30755' });
const folderName = path.join(tmpWorkspace, '!@#$% тест with spaces and 😊');

await exec('npm i playwright [email protected]');
await fs.promises.mkdir(folderName);
for (const file of ['electron-app.js', 'sanity-electron.js'])
await fs.promises.copyFile(path.join(tmpWorkspace, file), path.join(folderName, file));
await exec('node sanity-electron.js', {
cwd: path.join(folderName)
});
});

0 comments on commit 7dfa031

Please sign in to comment.