You've already forked joplin
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:
@@ -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/simpleBackup.spec.js
|
||||||
packages/app-desktop/integration-tests/util/activateMainMenuItem.js
|
packages/app-desktop/integration-tests/util/activateMainMenuItem.js
|
||||||
packages/app-desktop/integration-tests/util/createStartupArgs.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/extendedExpect.js
|
||||||
packages/app-desktop/integration-tests/util/getImageSourceSize.js
|
packages/app-desktop/integration-tests/util/getImageSourceSize.js
|
||||||
packages/app-desktop/integration-tests/util/getMainWindow.js
|
packages/app-desktop/integration-tests/util/getMainWindow.js
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -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/simpleBackup.spec.js
|
||||||
packages/app-desktop/integration-tests/util/activateMainMenuItem.js
|
packages/app-desktop/integration-tests/util/activateMainMenuItem.js
|
||||||
packages/app-desktop/integration-tests/util/createStartupArgs.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/extendedExpect.js
|
||||||
packages/app-desktop/integration-tests/util/getImageSourceSize.js
|
packages/app-desktop/integration-tests/util/getImageSourceSize.js
|
||||||
packages/app-desktop/integration-tests/util/getMainWindow.js
|
packages/app-desktop/integration-tests/util/getMainWindow.js
|
||||||
|
@@ -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;
|
@@ -1,7 +1,8 @@
|
|||||||
import { ElectronApplication } from '@playwright/test';
|
import { ElectronApplication } from '@playwright/test';
|
||||||
|
import evaluateWithRetry from './evaluateWithRetry';
|
||||||
|
|
||||||
const setDarkMode = (app: ElectronApplication, darkMode: boolean) => {
|
const setDarkMode = (app: ElectronApplication, darkMode: boolean) => {
|
||||||
return app.evaluate(({ nativeTheme }, darkMode) => {
|
return evaluateWithRetry(app, ({ nativeTheme }, darkMode) => {
|
||||||
nativeTheme.themeSource = darkMode ? 'dark' : 'light';
|
nativeTheme.themeSource = darkMode ? 'dark' : 'light';
|
||||||
}, darkMode);
|
}, darkMode);
|
||||||
};
|
};
|
||||||
|
@@ -5,6 +5,7 @@ import uuid from '@joplin/lib/uuid';
|
|||||||
import createStartupArgs from './createStartupArgs';
|
import createStartupArgs from './createStartupArgs';
|
||||||
import getMainWindow from './getMainWindow';
|
import getMainWindow from './getMainWindow';
|
||||||
import setDarkMode from './setDarkMode';
|
import setDarkMode from './setDarkMode';
|
||||||
|
import evaluateWithRetry from './evaluateWithRetry';
|
||||||
|
|
||||||
|
|
||||||
type StartWithPluginsResult = { app: ElectronApplication; mainWindow: Page };
|
type StartWithPluginsResult = { app: ElectronApplication; mainWindow: Page };
|
||||||
@@ -32,8 +33,8 @@ const initializeMainWindow = async (electronApp: ElectronApplication) => {
|
|||||||
return mainWindow;
|
return mainWindow;
|
||||||
};
|
};
|
||||||
|
|
||||||
const waitForMainMessage = (electronApp: ElectronApplication, messageId: string) => {
|
const waitForMainMessage = async (electronApp: ElectronApplication, messageId: string) => {
|
||||||
return electronApp.evaluate(({ ipcMain }, messageId) => {
|
return evaluateWithRetry(electronApp, ({ ipcMain }, messageId) => {
|
||||||
return new Promise<void>(resolve => {
|
return new Promise<void>(resolve => {
|
||||||
ipcMain.once(messageId, () => resolve());
|
ipcMain.once(messageId, () => resolve());
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user