UNPKG

e2ed

Version:

E2E testing framework over Playwright

42 lines (41 loc) 1.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.waitForNewTab = void 0; const internal_1 = require("../../constants/internal"); const testRunPromise_1 = require("../../context/testRunPromise"); const step_1 = require("../../step"); const useContext_1 = require("../../useContext"); const asserts_1 = require("../../utils/asserts"); const config_1 = require("../../utils/config"); const fn_1 = require("../../utils/fn"); const getDurationWithUnits_1 = require("../../utils/getDurationWithUnits"); /** * Waits for opening of new tab and returns this tab. */ exports.waitForNewTab = (async (triggerOrOptions, options) => { const trigger = typeof triggerOrOptions === 'function' ? triggerOrOptions : undefined; const finalOptions = typeof triggerOrOptions === 'function' ? options : (triggerOrOptions ?? options); const timeout = finalOptions?.timeout ?? (0, config_1.getFullPackConfig)().navigationTimeout; const timeoutWithUnits = (0, getDurationWithUnits_1.getDurationWithUnits)(timeout); if (trigger !== undefined) { (0, fn_1.setCustomInspectOnFunction)(trigger); } let newTab; await (0, step_1.step)(`Wait for new tab with timeout ${timeoutWithUnits}`, async () => { const context = (0, useContext_1.getPlaywrightPage)().context(); const pagePromise = context.waitForEvent('page', { timeout }); await trigger?.(); const testRunPromise = (0, testRunPromise_1.getTestRunPromise)(); const page = await Promise.race([pagePromise, testRunPromise]); newTab = { page: page ?? {} }; const url = page?.url(); return { url }; }, { payload: { timeoutWithUnits, trigger }, skipLogs: finalOptions?.skipLogs ?? false, timeout: timeout + internal_1.ADDITIONAL_STEP_TIMEOUT, type: 7 /* LogEventType.InternalCore */, }); (0, asserts_1.assertValueIsDefined)(newTab, 'newTab is defined', { trigger }); return newTab; });