UNPKG

@alphabin/trx

Version:

TRX reporter for Playwright tests with Azure Blob Storage upload support

97 lines (96 loc) 3.27 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Config = void 0; const path_1 = __importDefault(require("path")); const fileSystem_util_1 = require("./utils/fileSystem.util"); const logger_util_1 = __importDefault(require("./utils/logger.util")); /** * Default configuration options */ const DEFAULT_OPTIONS = { collectGitMetadata: true, collectCiMetadata: true, collectSystemMetadata: true, disableUpload: false, reportDir: './test-results', debug: false, timeout: 30000, retries: 3 }; /** * Configuration class for TRX reporter */ class Config { constructor(options) { // Check for required options if (!options.serverUrl) { throw new Error('TRX server URL is required'); } if (!options.apiKey) { throw new Error('TRX API key is required'); } // Merge with default options this.options = { ...DEFAULT_OPTIONS, ...options }; // Setup logger debug mode if (this.options.debug) { logger_util_1.default.debug('Debug mode enabled'); process.env.DEBUG = process.env.DEBUG ? `${process.env.DEBUG},testreportx:*` : 'testreportx:*'; } // Normalize server URL if (this.options.serverUrl.endsWith('/')) { this.options.serverUrl = this.options.serverUrl.slice(0, -1); } // Normalize report directory path if (this.options.reportDir) { this.options.reportDir = path_1.default.resolve(this.options.reportDir); } logger_util_1.default.debug('Configuration initialized', this.options); } /** * Gets the configuration options */ get() { return this.options; } /** * Checks if upload is enabled */ isUploadEnabled() { return !this.options.disableUpload; } /** * Creates a configuration from a playwright config file */ static fromPlaywrightConfig(configDir, options) { logger_util_1.default.debug(`Loading configuration from playwright config in ${configDir}`); try { const packageJson = (0, fileSystem_util_1.findPackageJson)(configDir); const playwrightConfig = packageJson?.playwright || {}; // Look for TRX configuration in playwright config const testFlowXConfig = playwrightConfig.testFlowX || {}; // Merge configurations return new Config({ ...testFlowXConfig, ...options }); } catch (error) { logger_util_1.default.error('Failed to load configuration from playwright config', error); // Fall back to provided options or throw error if required options are missing if (options?.serverUrl && options?.apiKey) { return new Config(options); } throw new Error('TRX configuration is required (serverUrl and apiKey)'); } } } exports.Config = Config; exports.default = Config;