Skip to content

Commit

Permalink
Wait for app startup to finish before running tests
Browse files Browse the repository at this point in the history
  • Loading branch information
personalizedrefrigerator committed Nov 19, 2024
1 parent 0f214e8 commit 0fa85ad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/app-desktop/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,9 @@ class Application extends BaseApplication {
SearchEngine.instance().scheduleSyncTables();
});

// Used by tests
ipcRenderer.send('startup-finished');

// setTimeout(() => {
// void populateDatabase(reg.db(), {
// clearDatabase: true,
Expand Down
20 changes: 16 additions & 4 deletions packages/app-desktop/integration-tests/util/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,20 @@ const getAndResizeMainWindow = async (electronApp: ElectronApplication) => {
return mainWindow;
};

const waitForStartupPlugins = async (electronApp: ElectronApplication) => {
return electronApp.evaluate(({ ipcMain }) => {
const waitForMainMessage = (electronApp: ElectronApplication, messageId: string) => {
return electronApp.evaluate(({ ipcMain }, messageId) => {
return new Promise<void>(resolve => {
ipcMain.once('startup-plugins-loaded', () => resolve());
ipcMain.once(messageId, () => resolve());
});
});
}, messageId);
};

const waitForAppLoaded = async (electronApp: ElectronApplication) => {
await waitForMainMessage(electronApp, 'startup-finished');
};

const waitForStartupPlugins = async (electronApp: ElectronApplication) => {
await waitForMainMessage(electronApp, 'startup-plugins-loaded');
};

const testDir = dirname(__dirname);
Expand All @@ -62,7 +70,9 @@ export const test = base.extend<JoplinFixtures>({
electronApp: async ({ profileDirectory }, use) => {
const startupArgs = createStartupArgs(profileDirectory);
const electronApp = await electron.launch({ args: startupArgs });
const startupPromise = waitForAppLoaded(electronApp);
await setDarkMode(electronApp, false);
await startupPromise;

await use(electronApp);

Expand All @@ -85,8 +95,10 @@ export const test = base.extend<JoplinFixtures>({
pluginPaths.map(path => resolve(testDir, path)).join(','),
],
});
const startupPromise = waitForAppLoaded(electronApp);
const mainWindowPromise = getAndResizeMainWindow(electronApp);
await waitForStartupPlugins(electronApp);
await startupPromise;

return {
app: electronApp,
Expand Down

0 comments on commit 0fa85ad

Please sign in to comment.