UNPKG

@applitools/eyes-playwright

Version:
71 lines (70 loc) 3.48 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getFinalEyesConfiguration = void 0; const name_1 = require("./batch/name"); const path_1 = __importDefault(require("path")); function addConfigurationProperties({ properties = [], testInfo, }) { const result = [ ...properties, { name: 'Playwright title path', value: `${path_1.default.relative(process.cwd(), testInfo.file)}:${testInfo.line} > ${testInfo.titlePath .slice(1) .join(' > ')}`, }, { name: 'Playwright worker index', value: String(testInfo.workerIndex) }, { name: 'Playwright parallel index', value: String(testInfo.parallelIndex) }, ...testInfo.tags.map(tag => ({ name: tag, value: tag })), ...testInfo.annotations.map(annotation => ({ name: annotation.type, value: String(annotation.description) })), ]; if (testInfo.config.projects.length > 1) { result.push({ name: 'Playwright project name', value: testInfo.project.name }); } if (testInfo.retry > 0) { properties.push({ name: 'Playwright retry', value: String(testInfo.retry) }); } if (testInfo.expectedStatus !== 'passed') { properties.push({ name: 'Playwright expected status', value: testInfo.expectedStatus }); } return result; } function addBatchDefaults({ configuration }) { var _a, _b, _c, _d; const batch = (_a = configuration.batch) !== null && _a !== void 0 ? _a : {}; (_b = batch.id) !== null && _b !== void 0 ? _b : (batch.id = `generated-${process.ppid}`); (_c = batch.name) !== null && _c !== void 0 ? _c : (batch.name = (0, name_1.getBatchName)({ appName: configuration.appName })); (_d = batch.properties) !== null && _d !== void 0 ? _d : (batch.properties = []); batch.properties.push({ name: 'CI', value: process.env.CI ? 'true' : 'false' }); try { batch.properties.push({ name: 'Playwright version', value: require('playwright-core/package.json').version }); } catch { // NOTE: ignore error } return batch; } function getFinalEyesConfiguration({ playwrightConfig = {}, projectConfig = {}, eyesConfig = {}, testInfo, }) { var _a, _b, _c; const configuration = { ...playwrightConfig, ...projectConfig, ...eyesConfig, }; (_a = configuration.appName) !== null && _a !== void 0 ? _a : (configuration.appName = 'My App'); (_b = configuration.testName) !== null && _b !== void 0 ? _b : (configuration.testName = testInfo.titlePath.slice(1).join(' > ')); configuration.properties = addConfigurationProperties({ properties: configuration.properties, testInfo }); configuration.batch = addBatchDefaults({ configuration }); (_c = configuration.stitchMode) !== null && _c !== void 0 ? _c : (configuration.stitchMode = 'CSS'); configuration.forceFullPageScreenshot = true; const displayName = typeof configuration.displayName === 'function' ? configuration.displayName(testInfo) : configuration.displayName; const testName = typeof configuration.testName === 'function' ? configuration.testName(testInfo) : configuration.testName; return { ...configuration, displayName, testName, }; } exports.getFinalEyesConfiguration = getFinalEyesConfiguration;