UNPKG

sealights-playwright-plugin

Version:

Playwright plugin for Sealights integration.

67 lines 3.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.test = void 0; const test_1 = require("@playwright/test"); const utils_1 = require("./utils"); const disableSealights = utils_1.SealightsConfig.getEnvVar(utils_1.consts.SL_ENVIRONMENT.DISABLE_SEALIGHTS, true); if (disableSealights) { utils_1.logger.info('Sealights is disabled, skipping Sealights fixtures initialization. The tests will run without Sealights integration.'); } const DEFAULT_FIXTURE_TIMEOUT = 60 * 1000; const sealightsTestService = utils_1.SealightsTestSessionService.getInstance(); exports.test = disableSealights ? test_1.test : test_1.test.extend({ forEachWorker: [ async ({}, use) => { await sealightsTestService.init(); await sealightsTestService.createTestSession(); await sealightsTestService.getTestRecommendations(); await use(); await sealightsTestService.endTestSession(); }, { scope: 'worker', auto: true, timeout: DEFAULT_FIXTURE_TIMEOUT, title: 'Sealights Setup and Teardown', }, ], forEachTest: [ async ({ page }, use, testInfo) => { await page.evaluate(({ consts }) => { window[consts.SL_WINDOW] = window[consts.SL_WINDOW] || {}; window[consts.SL_WINDOW][consts.SL_SKIP_AGENT] = true; }, { consts: utils_1.consts }); const shouldSkipTest = await sealightsTestService.shouldSkipTest(testInfo); if (shouldSkipTest) { exports.test.skip(true, `Test ${testInfo.title} (${testInfo.titlePath}) is excluded by Sealights TIA recommendation.`); } await use(); await sealightsTestService.sendTestEvent(testInfo); const componentCoverageData = await page.evaluate(() => { const coverageObjectPrefix = '$SealightsCoverage_'; const keys = Object.keys(window).filter((key) => key.includes(coverageObjectPrefix)); return keys.map((sealightsCoverageKey) => { const componentBsid = sealightsCoverageKey.replace(coverageObjectPrefix, ''); return { buildSessionId: componentBsid, coverage: window[sealightsCoverageKey], }; }); }); const coverage = componentCoverageData.map((componentCoverage) => ({ buildSessionId: componentCoverage.buildSessionId, coverage: utils_1.coverageUtils.mapIstanbulCoverage(componentCoverage.coverage), })); utils_1.logger.debug(`Successfully mapped coverage for test ${testInfo.title}, found ${coverage.length} components.`); await sealightsTestService.sendCoverage(testInfo.title, coverage); }, { auto: true, timeout: DEFAULT_FIXTURE_TIMEOUT, title: 'Sealights Lifecycle Hooks', }, ], }); //# sourceMappingURL=fixtures.js.map