UNPKG

electron-playwright-helpers

Version:

Helper functions for Electron end-to-end testing using Playwright

44 lines 2.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.electronWaitForFunction = electronWaitForFunction; exports.evaluateWithRetry = evaluateWithRetry; const utilities_1 = require("./utilities"); /** * Wait for a function to evaluate to true in the main Electron process. This really * should be part of the Playwright API, but it's not. * * This function is to `electronApp.evaluate()` * as `page.waitForFunction()` is `page.evaluate()`. * * @param electronApp {ElectronApplication} - the Playwright ElectronApplication * @param fn {Function} - the function to evaluate in the main process - must return a boolean * @param arg {Any} optional - an argument to pass to the function * @returns {Promise<void>} * @fulfil {void} Resolves when the function returns true */ async function electronWaitForFunction(electronApp, fn, arg, options = {}) { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore while (!(await (0, utilities_1.retry)(() => electronApp.evaluate(fn, arg), options))) { // wait 100ms before trying again await new Promise((resolve) => setTimeout(resolve, 100)); } } /** * Electron's `evaluate` function can be flakey, * throwing an error saying the execution context has been destroyed. * This function retries the evaluation several times to see if it can * run the evaluation without an error. If it fails after the retries, * it throws the error. * * @param electronApp {ElectronApplication} - the Playwright ElectronApplication * @param fn {Function} - the function to evaluate in the main process * @param arg {Any} - an argument to pass to the function * @param retries - the number of times to retry the evaluation * @param retryIntervalMs - the interval between retries * @returns {Promise<R>} - the result of the evaluation */ async function evaluateWithRetry(electronApp, fn, arg = {}, options = {}) { return (0, utilities_1.retry)(() => electronApp.evaluate(fn, arg), options); } //# sourceMappingURL=general_helpers.js.map