1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-08-10 22:11:50 +02:00

Chore: Desktop: Fix electronApp.evaluate-related test failure (#12216)

This commit is contained in:
Henry Heino
2025-05-19 14:59:31 -07:00
committed by GitHub
parent e65fbecef0
commit dc786e8178
5 changed files with 31 additions and 3 deletions

View File

@@ -535,6 +535,7 @@ packages/app-desktop/integration-tests/sidebar.spec.js
packages/app-desktop/integration-tests/simpleBackup.spec.js
packages/app-desktop/integration-tests/util/activateMainMenuItem.js
packages/app-desktop/integration-tests/util/createStartupArgs.js
packages/app-desktop/integration-tests/util/evaluateWithRetry.js
packages/app-desktop/integration-tests/util/extendedExpect.js
packages/app-desktop/integration-tests/util/getImageSourceSize.js
packages/app-desktop/integration-tests/util/getMainWindow.js

1
.gitignore vendored
View File

@@ -509,6 +509,7 @@ packages/app-desktop/integration-tests/sidebar.spec.js
packages/app-desktop/integration-tests/simpleBackup.spec.js
packages/app-desktop/integration-tests/util/activateMainMenuItem.js
packages/app-desktop/integration-tests/util/createStartupArgs.js
packages/app-desktop/integration-tests/util/evaluateWithRetry.js
packages/app-desktop/integration-tests/util/extendedExpect.js
packages/app-desktop/integration-tests/util/getImageSourceSize.js
packages/app-desktop/integration-tests/util/getMainWindow.js

View File

@@ -0,0 +1,24 @@
import { ElectronApplication } from '@playwright/test';
import type { PageFunctionOn } from 'playwright-core/types/structs';
import type * as ElectronType from 'electron';
const evaluateWithRetry = async <ReturnType, Arg> (
app: ElectronApplication,
pageFunction: PageFunctionOn<typeof ElectronType, Arg, ReturnType>,
arg: Arg,
) => {
let lastError;
const maxRetries = 3;
for (let retryIndex = 0; retryIndex < maxRetries; retryIndex ++) {
try {
return await app.evaluate(pageFunction, arg);
} catch (error) {
console.error('app.evaluate failed:', error, `Retrying... ${retryIndex}/${maxRetries}`);
lastError = error;
}
}
throw lastError;
};
export default evaluateWithRetry;

View File

@@ -1,7 +1,8 @@
import { ElectronApplication } from '@playwright/test';
import evaluateWithRetry from './evaluateWithRetry';
const setDarkMode = (app: ElectronApplication, darkMode: boolean) => {
return app.evaluate(({ nativeTheme }, darkMode) => {
return evaluateWithRetry(app, ({ nativeTheme }, darkMode) => {
nativeTheme.themeSource = darkMode ? 'dark' : 'light';
}, darkMode);
};

View File

@@ -5,6 +5,7 @@ import uuid from '@joplin/lib/uuid';
import createStartupArgs from './createStartupArgs';
import getMainWindow from './getMainWindow';
import setDarkMode from './setDarkMode';
import evaluateWithRetry from './evaluateWithRetry';
type StartWithPluginsResult = { app: ElectronApplication; mainWindow: Page };
@@ -32,8 +33,8 @@ const initializeMainWindow = async (electronApp: ElectronApplication) => {
return mainWindow;
};
const waitForMainMessage = (electronApp: ElectronApplication, messageId: string) => {
return electronApp.evaluate(({ ipcMain }, messageId) => {
const waitForMainMessage = async (electronApp: ElectronApplication, messageId: string) => {
return evaluateWithRetry(electronApp, ({ ipcMain }, messageId) => {
return new Promise<void>(resolve => {
ipcMain.once(messageId, () => resolve());
});