Skip to content

Commit

Permalink
asdf
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkpickering committed Feb 9, 2023
1 parent 3ba5abb commit 40773ac
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
46 changes: 33 additions & 13 deletions e2e/quit-on-close.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { test, expect, _electron, } from '@playwright/test';
import util from 'util';

import { test, expect, _electron, ElectronApplication } from '@playwright/test';

import { createDefaultSettings, packageLogs, startRancherDesktop } from './utils/TestUtils';

const sleep = util.promisify(setTimeout);

/**
* Using test.describe.serial make the test execute step by step, as described on each `test()` order
* Playwright executes test in parallel by default and it will not work for our app backend loading process.
Expand All @@ -13,23 +17,39 @@ test.describe.serial('quitOnClose setting', () => {

test('should quit when quitOnClose is true and window is closed', async() => {
createDefaultSettings({ window: { quitOnClose: true } });
const {app, page} = await startRancherDesktop(__filename);
const browserWindowHandle = await app.browserWindow(page);
const { electronApp, page } = await startRancherDesktop(__filename);
const browserWindowHandle = await electronApp.browserWindow(page);

browserWindowHandle.evaluate((browserWindow: Electron.BrowserWindow) => browserWindow.close());
// Rancher Desktop should be closed by this point. This means that
// app.close() will throw an error, which we consider to be success
// for this test.
await expect(app.close()).rejects.toThrow();
await expect(pollForQuit(electronApp)).resolves.toBe(true);
});

test('should not quit when quitOnClose is false and window is closed', async() => {
createDefaultSettings({ window: { quitOnClose: false } });
const {app, page} = await startRancherDesktop(__filename);
const browserWindowHandle = await app.browserWindow(page);
const { electronApp, page } = await startRancherDesktop(__filename);
const browserWindowHandle = await electronApp.browserWindow(page);

browserWindowHandle.evaluate((browserWindow: Electron.BrowserWindow) => browserWindow.close());
// Rancher Desktop should not be closed, because quitOnClose is false.
// So, calling app.close() should succeed, which we consider to be success
// for this test.
await expect(app.close()).resolves.not.toThrow();
await expect(pollForQuit(electronApp)).resolves.toBe(false);
});
});

async function pollForQuit(electronApp: ElectronApplication): Promise<boolean> {
let hasQuit = false;

electronApp.process().on('close', () => {
hasQuit = true;
});

const sleepTime = 5000;
const iterCount = 6;

for (let i = 0; i < iterCount; i++) {
if (hasQuit) {
return true;
}
await sleep(sleepTime);
}

return false;
}
9 changes: 5 additions & 4 deletions e2e/utils/TestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ export async function retry<T>(proc: () => Promise<T>, options?: { delay?: numbe
* playwright objects when it has started.
* @param testPath The path to the test file.
*/
export async function startRancherDesktop(testPath: string): Promise<{app: ElectronApplication, page: Page}> {
export async function startRancherDesktop(testPath: string): Promise<{electronApp: ElectronApplication, page: Page}> {
const electronApp = await _electron.launch({
args: [
path.join(__dirname, '../'),
path.join(__dirname, '../../'),
'--disable-gpu',
'--whitelisted-ips=',
// See pkg/rancher-desktop/utils/commandLine.ts before changing the next item as the final option.
Expand All @@ -189,10 +189,11 @@ export async function startRancherDesktop(testPath: string): Promise<{app: Elect
],
env: {
...process.env,
RD_LOGS_DIR: reportAsset(testPath, 'log'),
RD_LOGS_DIR: reportAsset(testPath, 'log'),
RD_MOCK_BACKEND: '1',
},
});
const page = await electronApp.firstWindow();
return {app: electronApp, page: page};

return { electronApp, page };
}

0 comments on commit 40773ac

Please sign in to comment.