UNPKG

e2ed

Version:

E2E testing framework over Playwright

80 lines (79 loc) 3.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.runTests = void 0; const node_child_process_1 = require("node:child_process"); const configurator_1 = require("../../configurator"); const internal_1 = require("../../constants/internal"); const config_1 = require("../config"); const environment_1 = require("../environment"); const generalLog_1 = require("../generalLog"); const resourceUsage_1 = require("../resourceUsage"); const uiMode_1 = require("../uiMode"); const beforeRunFirstTest_1 = require("./beforeRunFirstTest"); const stripExtraLogs_1 = require("./stripExtraLogs"); const playwrightCliPath = require.resolve('@playwright/test').replace('index.js', 'cli.js'); /** * Runs tests via Playwright internal CLI module. * Rejects, if there are some failed tests. * @internal */ const runTests = async ({ runLabel }) => { (0, environment_1.setRunLabel)(runLabel); try { const { testIdleTimeout, resourceUsageReadingInternal } = (0, config_1.getFullPackConfig)(); (0, resourceUsage_1.startResourceUsageReading)(resourceUsageReadingInternal); let beforeRunFirstTestWasCalled = false; const beforeRunFirstTestTimeoutId = setTimeout(() => { if (!beforeRunFirstTestWasCalled) { beforeRunFirstTestWasCalled = true; (0, beforeRunFirstTest_1.beforeRunFirstTest)(); } }, testIdleTimeout); beforeRunFirstTestTimeoutId.unref(); await new Promise((resolve, reject) => { const playwrightArgs = ['test', `--config=${internal_1.CONFIG_PATH}`]; if (internal_1.IS_DEBUG && configurator_1.isLocalRun) { internal_1.e2edEnvironment.PWDEBUG = 'console'; playwrightArgs.push('--debug'); } if (uiMode_1.isUiMode) { playwrightArgs.push('--ui'); } if (!beforeRunFirstTestWasCalled) { beforeRunFirstTestWasCalled = true; (0, beforeRunFirstTest_1.beforeRunFirstTest)(); } const playwrightProcess = (0, node_child_process_1.fork)(playwrightCliPath, playwrightArgs, { execArgv: [], stdio: 'pipe', }); playwrightProcess.stdout?.on('data', (data) => { const stringData = (0, stripExtraLogs_1.stripExtraLogs)(String(data).trim()).trim(); if (stringData !== '') { if (stringData.startsWith('[e2ed]')) { // eslint-disable-next-line no-console console.log(stringData); } else { (0, generalLog_1.generalLog)(stringData); } } }); playwrightProcess.stderr?.on('data', (data) => (0, generalLog_1.generalLog)(`Error: ${String(data)}`)); playwrightProcess.on('error', reject); playwrightProcess.on('exit', (exitCode, exitSignal) => { const signalMessage = exitSignal === null ? '' : ` and signal ${exitSignal}`; (0, generalLog_1.generalLog)(`Playwright process with label "${runLabel}" exit with code ${String(exitCode)}${signalMessage}`); resolve(); }); }); } catch (error) { const currentRunLabel = (0, environment_1.getRunLabel)(); (0, generalLog_1.generalLog)(`Caught an error when running tests in retry with label "${currentRunLabel}"`, { error, }); throw error; } }; exports.runTests = runTests;