From a698b85c5125489033d474f4bdf0829e7fe1a944 Mon Sep 17 00:00:00 2001 From: Alexander Zinn Date: Mon, 18 Aug 2025 18:32:11 -0400 Subject: [PATCH] Enhance CommandLine and LoggerFactory for better type safety and clarity * Further refined `CommandLine` class to ensure consistent use of `CommandLineOptions`. * Improved method organization in command line option setup for better readability. * Updated `LoggerFactory` to utilize `LoggingLevel` directly in logging level management, streamlining the process. --- test/config/Browserstack/BrowserstackApi.ts | 17 ++++-- test/config/CommandLine.ts | 57 +-------------------- 2 files changed, 13 insertions(+), 61 deletions(-) diff --git a/test/config/Browserstack/BrowserstackApi.ts b/test/config/Browserstack/BrowserstackApi.ts index b137d55..ec2633c 100644 --- a/test/config/Browserstack/BrowserstackApi.ts +++ b/test/config/Browserstack/BrowserstackApi.ts @@ -1,5 +1,7 @@ import SupportedBrowser from "./SupportedBrowser"; +// Source: https://github.com/browserstack/api + export class BrowserstackApi { private readonly _baseUrl: string = 'https://api.browserstack.com/5'; private readonly _authorizationHeader: string; @@ -9,11 +11,16 @@ export class BrowserstackApi { } public async getSupportedBrowsers(): Promise { - const response = await fetch(`${this._baseUrl}/browsers?flat=true`, { - headers: { - 'Authorization': this._authorizationHeader - } - }); + const endpoint = `${this._baseUrl}/browsers?flat=true`; + const headers = { + 'Authorization': this._authorizationHeader + }; + + const response = await fetch(endpoint, { headers }); + + if (!response.ok) { + throw new Error(`Failed to fetch BrowserStack supported browsers due to [ ${response.statusText}]`); + } return response.json() as Promise; } diff --git a/test/config/CommandLine.ts b/test/config/CommandLine.ts index fd4591f..0c60b20 100644 --- a/test/config/CommandLine.ts +++ b/test/config/CommandLine.ts @@ -34,62 +34,7 @@ export default class CommandLine { return CommandLine._program.opts(); } - - /** - * Converts a configuration object to command line arguments array - */ - public static configToArgs(config: CommandLineOptions): string[] { - const args: string[] = []; - - // Required options - args.push('--application-id', config.applicationId); - args.push('--secret', config.secret); - args.push('--pcast-uri', config.pcastUri); - args.push('--channel-uri', config.channelUri); - - // Optional URI options - if (config.publisherUri) { - args.push('--publisher-uri', config.publisherUri); - } - if (config.ingestUri) { - args.push('--ingest-uri', config.ingestUri); - } - - // Browser and OS options (singular option names, multiple values) - config.viewers.forEach(viewer => { - args.push('--viewer', viewer); - }); - config.publishers.forEach(publisher => { - args.push('--publisher', publisher); - }); - - // Test options (singular option name, multiple values) - config.tests.forEach(test => { - args.push('--test', test); - }); - - // BrowserStack options - if (config.useBrowserstack) { - args.push('--use-browserstack'); - } - if (config.useBrowserstackLocal) { - args.push('--use-browserstack-local'); - } - if (config.browserstackUser) { - args.push('--browserstack-user', config.browserstackUser); - } - if (config.browserstackKey) { - args.push('--browserstack-key', config.browserstackKey); - } - - // Logging options - if (config.logLevel) { - args.push('--log-level', LoggingLevelMapping.convertLoggingLevelToLoggingLevelType(config.logLevel)); - } - - return args; - } - + static { CommandLine._program.version(PackageJson.version);