Skip to content

Commit 91b2cc8

Browse files
committed
maximize the window in e2e tests in electron
1 parent 36e8fb4 commit 91b2cc8

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

packages/compass-e2e-tests/helpers/compass.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,19 +1020,28 @@ export async function init(
10201020
// For browser.executeAsync(). Trying to see if it will work for browser.execute() too.
10211021
await browser.setTimeout({ script: 5_000 });
10221022

1023-
// larger window for more consistent results
1024-
const [width, height] = await browser.execute(() => {
1025-
// in case setWindowSize() below doesn't work
1026-
window.resizeTo(window.screen.availWidth, window.screen.availHeight);
1023+
if (TEST_COMPASS_WEB) {
1024+
// larger window for more consistent results
1025+
const [width, height] = await browser.execute(() => {
1026+
// in case setWindowSize() below doesn't work
1027+
window.resizeTo(window.screen.availWidth, window.screen.availHeight);
10271028

1028-
return [window.screen.availWidth, window.screen.availHeight];
1029-
});
1030-
debug(`available width=${width}, height=${height}`);
1031-
try {
1032-
// window.resizeTo() doesn't work on firefox
1033-
await browser.setWindowSize(width, height);
1034-
} catch (err: any) {
1035-
console.error(err?.stack);
1029+
return [window.screen.availWidth, window.screen.availHeight];
1030+
});
1031+
// getting available width=1512, height=944 in electron on mac which is arbitrary
1032+
debug(`available width=${width}, height=${height}`);
1033+
try {
1034+
// window.resizeTo() doesn't work on firefox
1035+
await browser.setWindowSize(width, height);
1036+
} catch (err: any) {
1037+
console.error(err?.stack);
1038+
}
1039+
} else {
1040+
await browser.execute(() => {
1041+
// eslint-disable-next-line @typescript-eslint/no-var-requires
1042+
const { ipcRenderer } = require('electron');
1043+
ipcRenderer.invoke('compass:maximize');
1044+
});
10361045
}
10371046

10381047
if (compass.needsCloseWelcomeModal) {

packages/compass/src/main/window-manager.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,14 @@ class CompassWindowManager {
276276
shell.showItemInFolder(filename);
277277
});
278278

279+
// To resize an electron window you have to do it from the main process.
280+
// This is here so that the e2e tests can resize the window from the
281+
// renderer process.
282+
ipcMain?.handle('compass:maximize', () => {
283+
const first = BrowserWindow.getAllWindows()[0];
284+
first.maximize();
285+
});
286+
279287
await electronApp.whenReady();
280288
await onAppReady();
281289

0 commit comments

Comments
 (0)