Skip to content

Commit

Permalink
test: improve e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cawa-93 committed Dec 17, 2022
1 parent ebd17dc commit 5a64e0f
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions tests/e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type {ElectronApplication} from 'playwright';
import type {ElectronApplication, JSHandle} from 'playwright';
import {_electron as electron} from 'playwright';
import {afterAll, beforeAll, expect, test} from 'vitest';
import {createHash} from 'crypto';
import type {BrowserWindow} from 'electron';

let electronApp: ElectronApplication;

Expand All @@ -14,22 +15,27 @@ afterAll(async () => {
});

test('Main window state', async () => {
const windowState: {isVisible: boolean; isDevToolsOpened: boolean; isCrashed: boolean} =
await electronApp.evaluate(({BrowserWindow}) => {
const mainWindow = BrowserWindow.getAllWindows()[0];

const page = await electronApp.firstWindow();
const window: JSHandle<BrowserWindow> = await electronApp.browserWindow(page);
const windowState = await window.evaluate(
(mainWindow): Promise<{isVisible: boolean; isDevToolsOpened: boolean; isCrashed: boolean}> => {
const getState = () => ({
isVisible: mainWindow.isVisible(),
isDevToolsOpened: mainWindow.webContents.isDevToolsOpened(),
isCrashed: mainWindow.webContents.isCrashed(),
});

return new Promise(resolve => {
/**
* The main window is created hidden, and is shown only when it is ready.
* See {@link ../packages/main/src/mainWindow.ts} function
*/
if (mainWindow.isVisible()) {
resolve(getState());
} else mainWindow.once('ready-to-show', () => setTimeout(() => resolve(getState()), 0));
} else mainWindow.once('ready-to-show', () => resolve(getState()));
});
});
},
);

expect(windowState.isCrashed, 'The app has crashed').toBeFalsy();
expect(windowState.isVisible, 'The main window was not visible').toBeTruthy();
Expand Down

0 comments on commit 5a64e0f

Please sign in to comment.