UNPKG

electron-playwright-helpers

Version:

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

74 lines 2.97 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.addTimeout = exports.addTimeoutToPromise = void 0; const helpers = __importStar(require("./")); /** * Add a timeout to any Promise * * @category Utilities * @see addTimeout * * @param promise - the promise to add a timeout to - must be a Promise * @param timeoutMs - the timeout in milliseconds - defaults to 5000 * @param timeoutMessage - optional - the message to return if the timeout is reached * * @returns {Promise<T>} the result of the original promise if it resolves before the timeout */ async function addTimeoutToPromise(promise, timeoutMs = 5000, timeoutMessage) { return new Promise((resolve, reject) => { setTimeout(() => { reject(timeoutMessage !== null && timeoutMessage !== void 0 ? timeoutMessage : `timeout after ${timeoutMs}ms`); }, timeoutMs); promise .then((result) => { resolve(result); }) .catch((error) => { reject(error); }); }); } exports.addTimeoutToPromise = addTimeoutToPromise; /** * Add a timeout to any helper function from this library which returns a Promise. * * @category Utilities * * @param functionName - the name of the helper function to call * @param timeoutMs - the timeout in milliseconds - defaults to 5000 * @param timeoutMessage - optional - the message to return if the timeout is reached * @param args - any arguments to pass to the helper function * * @returns {Promise<T>} the result of the helper function if it resolves before the timeout */ function addTimeout(functionName, timeoutMs = 5000, timeoutMessage, ...args) { return addTimeoutToPromise( // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore helpers[functionName](...args), timeoutMs, timeoutMessage); } exports.addTimeout = addTimeout; //# sourceMappingURL=utilities.js.map