UNPKG

e2ed

Version:

E2E testing framework over Playwright

42 lines (41 loc) 1.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.runStepBody = void 0; const stepsStackStorage_1 = require("../../context/stepsStackStorage"); const testIdleTimeout_1 = require("../../context/testIdleTimeout"); const error_1 = require("../error"); const getDurationWithUnits_1 = require("../getDurationWithUnits"); const promise_1 = require("../promise"); const test_1 = require("@playwright/test"); /** * Runs `step` body function. * @internal */ const runStepBody = async ({ body, errorProperties, logEvent, name, stepOptions, }) => { let payload = undefined; const timeout = stepOptions?.timeout ?? (0, testIdleTimeout_1.getTestIdleTimeout)(); const timeoutError = new error_1.E2edError(`Body of step "${name}" rejected after ${(0, getDurationWithUnits_1.getDurationWithUnits)(timeout)} timeout`, errorProperties); const runBody = async () => { if (logEvent !== undefined && typeof body === 'function') { const stepsStackStorage = (0, stepsStackStorage_1.getStepsStackStorage)(); payload = await stepsStackStorage.run(logEvent, body); } else { payload = await body?.(); } }; let bodyError; let hasError = false; const runBodyWithTimeout = () => (0, promise_1.addTimeoutToPromise)(runBody(), timeout, timeoutError).catch((error) => { bodyError = error; hasError = true; }); if (stepOptions?.runPlaywrightStep === true) { await test_1.test.step(name, () => runBodyWithTimeout()); } else { await runBodyWithTimeout(); } return { bodyError, hasError, payload }; }; exports.runStepBody = runStepBody;