文件
mynode/packages/app-desktop/integration-tests/util/waitForNextWindowMatching.ts
chen 301194963b
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
feat: Initial clean release of CHM
2026-11-04 11:29:39 +08:00

53 行
1.4 KiB
TypeScript

import { Second } from '@joplin/utils/time';
import { ElectronApplication, Page } from '@playwright/test';
const waitForNextWindowMatching = (titlePattern: RegExp, electronApp: ElectronApplication) => {
return new Promise<Page>((resolve, reject) => {
let timeout: NodeJS.Timeout|null = null;
const clearListenersAndTimeouts = () => {
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
electronApp.off('window', onWindowAdded);
electronApp.off('close', onClose);
};
const onWindowAdded = async (page: Page) => {
const title = await page.title();
if (title.match(titlePattern)) {
clearListenersAndTimeouts();
resolve(page);
}
};
const onClose = () => {
clearListenersAndTimeouts();
reject(new Error('Target application closed.'));
};
electronApp.on('window', onWindowAdded);
electronApp.on('close', onClose);
timeout = setTimeout(async () => {
timeout = null;
clearListenersAndTimeouts();
const windowTitles = await getOpenWindowTitles(electronApp);
reject(new Error(`Opening a window timed out. Open window titles: ${JSON.stringify(windowTitles)}.`));
}, 30 * Second);
});
};
export default waitForNextWindowMatching;
const getOpenWindowTitles = (electronApp: ElectronApplication) => {
const windows = electronApp.windows();
return Promise.all(windows.map(async w => {
try {
return await w.title();
} catch (error) {
return `(Error: ${error})`;
}
}));
};