1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Merge pull request #18325 from timvandermeij/integration-test-timeouts

Fix the timeout logic in the `waitForEvent` integration test helper function
This commit is contained in:
Tim van der Meij 2024-06-25 13:44:20 +02:00 committed by GitHub
commit 4b95d689de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -189,16 +189,22 @@ async function getSpanRectFromText(page, pageNumber, text) {
async function waitForEvent(page, eventName, timeout = 5000) {
const handle = await page.evaluateHandle(
(name, timeOut) => {
let callback = null;
let callback = null,
timeoutId = null;
return [
Promise.race([
new Promise(resolve => {
// add event listener and wait for event to fire before returning
callback = () => resolve(false);
callback = () => {
if (timeoutId) {
clearTimeout(timeoutId);
}
resolve(false);
};
document.addEventListener(name, callback, { once: true });
}),
new Promise(resolve => {
setTimeout(() => {
timeoutId = setTimeout(() => {
document.removeEventListener(name, callback);
resolve(true);
}, timeOut);