Skip to content

Commit

Permalink
maximize the window in e2e tests in electron
Browse files Browse the repository at this point in the history
  • Loading branch information
lerouxb committed Oct 11, 2024
1 parent 36e8fb4 commit 91b2cc8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
33 changes: 21 additions & 12 deletions packages/compass-e2e-tests/helpers/compass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1020,19 +1020,28 @@ export async function init(
// For browser.executeAsync(). Trying to see if it will work for browser.execute() too.
await browser.setTimeout({ script: 5_000 });

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

return [window.screen.availWidth, window.screen.availHeight];
});
debug(`available width=${width}, height=${height}`);
try {
// window.resizeTo() doesn't work on firefox
await browser.setWindowSize(width, height);
} catch (err: any) {
console.error(err?.stack);
return [window.screen.availWidth, window.screen.availHeight];
});
// getting available width=1512, height=944 in electron on mac which is arbitrary
debug(`available width=${width}, height=${height}`);
try {
// window.resizeTo() doesn't work on firefox
await browser.setWindowSize(width, height);
} catch (err: any) {
console.error(err?.stack);
}
} else {
await browser.execute(() => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { ipcRenderer } = require('electron');
ipcRenderer.invoke('compass:maximize');
});
}

if (compass.needsCloseWelcomeModal) {
Expand Down
8 changes: 8 additions & 0 deletions packages/compass/src/main/window-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@ class CompassWindowManager {
shell.showItemInFolder(filename);
});

// To resize an electron window you have to do it from the main process.
// This is here so that the e2e tests can resize the window from the
// renderer process.
ipcMain?.handle('compass:maximize', () => {
const first = BrowserWindow.getAllWindows()[0];
first.maximize();
});

await electronApp.whenReady();
await onAppReady();

Expand Down

0 comments on commit 91b2cc8

Please sign in to comment.