UNPKG

@alphabin/trx

Version:

TRX reporter for Playwright tests with Azure Blob Storage upload support

147 lines (146 loc) 5.54 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SystemCollector = exports.CICollector = exports.GitCollector = exports.MetadataCollector = void 0; const git_collector_1 = __importDefault(require("./git.collector")); exports.GitCollector = git_collector_1.default; const ci_collector_1 = __importDefault(require("./ci.collector")); exports.CICollector = ci_collector_1.default; const system_collector_1 = __importDefault(require("./system.collector")); exports.SystemCollector = system_collector_1.default; const logger_util_1 = __importDefault(require("../utils/logger.util")); /** * Main metadata collector that aggregates data from all collectors */ class MetadataCollector { constructor(options = {}) { this.rootDir = options.rootDir || process.cwd(); this.collectGit = options.collectGit !== false; // Default to true this.collectCI = options.collectCI !== false; // Default to true this.collectSystem = options.collectSystem !== false; // Default to true this.customMetadata = options.customMetadata; } /** * Collects metadata from all enabled collectors */ async collect() { logger_util_1.default.debug('Collecting metadata', { collectGit: this.collectGit, collectCI: this.collectCI, collectSystem: this.collectSystem }); // Initialize metadata structure with defaults; reporter will override test.params const metadata = { git: { branch: 'unknown', commit: { hash: '', message: '', author: '', email: '', timestamp: '' }, repository: { name: '', url: '' }, pr: { id: '', title: '', url: '' } }, ci: { provider: 'unknown', pipeline: { id: '', name: 'CI Pipeline', url: '' }, build: { number: 'unknown', trigger: '' }, environment: { name: 'local', type: '', os: 'unknown', node: 'unknown' } }, system: { hostname: 'unknown', cpu: { count: 0, model: '' }, memory: { total: '' }, os: 'unknown', nodejs: 'unknown', playwright: 'unknown' }, test: { config: { browsers: [], actualWorkers: 0, timeout: 0, preserveOutput: '', fullyParallel: false, forbidOnly: false, projects: 0, shard: null, reporters: [], }, customTags: [] } }; // Collect git metadata if enabled if (this.collectGit) { const gitCollector = new git_collector_1.default(this.rootDir); const gitData = await gitCollector.collect(); metadata.git = { ...metadata.git, ...gitData }; } // Collect CI metadata if enabled if (this.collectCI) { const ciCollector = new ci_collector_1.default(); const ciData = await ciCollector.collect(); metadata.ci = { ...metadata.ci, ...ciData }; } // Collect system metadata if enabled if (this.collectSystem) { const systemCollector = new system_collector_1.default(); const systemData = await systemCollector.collect(); metadata.system = { ...metadata.system, ...systemData }; } // Add custom metadata if provided if (this.customMetadata) { for (const [key, value] of Object.entries(this.customMetadata)) { const section = key.split('.')[0]; const field = key.split('.')[1]; if (section && field) { // Handle nested properties like 'test.customTags' metadata[section] = { ...metadata[section], [field]: value }; } else { // Handle top-level custom properties metadata[key] = value; } } } logger_util_1.default.debug('Collected metadata', metadata); return metadata; } /** * Gets browser information from environment variables */ getBrowserInfo() { const browserName = process.env.BROWSER || process.env.PLAYWRIGHT_BROWSER || 'chromium'; return browserName; } /** * Gets viewport information from environment variables */ getViewportInfo() { const width = process.env.VIEWPORT_WIDTH || process.env.WIDTH || '1280'; const height = process.env.VIEWPORT_HEIGHT || process.env.HEIGHT || '720'; return `${width}x${height}`; } /** * Determines if tests are running in headless mode */ isHeadless() { const headlessValue = process.env.HEADLESS || process.env.PLAYWRIGHT_HEADLESS; return headlessValue !== 'false'; } } exports.MetadataCollector = MetadataCollector; exports.default = MetadataCollector;