diff --git a/test/config/Browserstack/SupportedBrowser.ts b/test/config/Browserstack/SupportedBrowser.ts index ba90894..a14d572 100644 --- a/test/config/Browserstack/SupportedBrowser.ts +++ b/test/config/Browserstack/SupportedBrowser.ts @@ -7,4 +7,4 @@ type SupportedBrowser = { real_mobile: boolean; } -export default SupportedBrowser \ No newline at end of file +export default SupportedBrowser; \ No newline at end of file diff --git a/test/config/CommandLine.ts b/test/config/CommandLine.ts index fd873ed..cf5fcf2 100644 --- a/test/config/CommandLine.ts +++ b/test/config/CommandLine.ts @@ -5,7 +5,7 @@ import {LoggingLevel, LoggingLevelMapping} from '../logger/LoggingLevel'; export interface CommandLineOptions { applicationId: string; secret: string; - logLevel: string; + logLevel: LoggingLevel; pcastUri: string; ingestUri: string; channelUri: string; @@ -27,7 +27,7 @@ interface ConfigurationObject { useBrowserstackLocal: boolean; browserstackUser: string; browserstackKey: string; - logLevel: string; + logLevel: LoggingLevel; applicationId: string; secret: string; pcastUri: string; @@ -101,7 +101,7 @@ export default class CommandLine { // Logging options if (config.logLevel) { - args.push('--log-level', config.logLevel); + args.push('--log-level', LoggingLevelMapping.convertLoggingLevelToLoggingLevelType(config.logLevel)); } return args; diff --git a/test/config/example-usage.ts b/test/config/example-usage.ts deleted file mode 100644 index 8dd30c9..0000000 --- a/test/config/example-usage.ts +++ /dev/null @@ -1,43 +0,0 @@ -import CommandLine from './CommandLine'; - -// Example configuration object matching your structure -const config = { - viewers: ["chrome", "firefox"], - publishers: [], - tests: ["test/tests/real-time", "test/tests/dash", "test/tests/hls"], - useBrowserstack: false, - useBrowserstackLocal: false, - browserstackUser: "", - browserstackKey: "", - logLevel: "Info", - applicationId: "phenixrts.com-alex.zinn", - secret: "AMAsDzr.dIuGMZ.Zu52Dt~MQvP!DZwYg", - pcastUri: "https://pcast-stg.phenixrts.com", - ingestUri: "rtmp://ingest-stg.phenixrts.com:80/ingest", - channelUri: "https://pcast-stg.phenixrts.com/channel", -}; - -// Convert configuration to command line arguments -const args = CommandLine.configToArgs(config); - -console.log('Generated command line arguments:'); -console.log(args.join(' ')); - -console.log('\nThis generates the equivalent of:'); -console.log('--application-id phenixrts.com-alex.zinn \\'); -console.log('--secret AMAsDzr.dIuGMZ.Zu52Dt~MQvP!DZwYg \\'); -console.log('--pcast-uri https://pcast-stg.phenixrts.com \\'); -console.log('--channel-uri https://pcast-stg.phenixrts.com/channel \\'); -console.log('--ingest-uri rtmp://ingest-stg.phenixrts.com:80/ingest \\'); -console.log('--viewer chrome \\'); -console.log('--viewer firefox \\'); -console.log('--test test/tests/real-time \\'); -console.log('--test test/tests/dash \\'); -console.log('--test test/tests/hls \\'); -console.log('--log-level Info'); - -console.log('\nNote: Users can pass --viewer, --publisher, and -t multiple times to build arrays'); - -// You can now use these arguments with the CommandLine.parse method -// const options = CommandLine.parse(args); -// console.log('Parsed options:', options); diff --git a/test/logger/LoggerFactory.ts b/test/logger/LoggerFactory.ts index 1f3d63b..6006013 100644 --- a/test/logger/LoggerFactory.ts +++ b/test/logger/LoggerFactory.ts @@ -1,19 +1,19 @@ import { ConsoleAppender } from './appenders/ConsoleAppender'; import IAppender from './appenders/IAppender'; import {Logger} from './Logger'; -import {LoggingLevel} from './LoggingLevel'; +import {LoggingLevel, LoggingLevelMapping, LoggingLevelType} from './LoggingLevel'; import {Threshold} from './Threshold'; export default class LoggerFactory { private static readonly _loggerForCategory: Map = new Map(); - private static readonly _threshold: Threshold = new Threshold({level: LoggingLevel.Debug}); + private static readonly _threshold: {level: LoggingLevel} = {level: LoggingLevel.Info}; private static readonly _appenders: IAppender[] = [new ConsoleAppender()]; public static getLogger(category: string): Logger { let logger = LoggerFactory._loggerForCategory.get(category); if (logger === undefined) { - logger = new Logger({category, threshold: LoggerFactory._threshold, appenders: LoggerFactory._appenders}); + logger = new Logger({category, threshold: new Threshold(LoggerFactory._threshold), appenders: LoggerFactory._appenders}); LoggerFactory._loggerForCategory.set(category, logger); } @@ -21,6 +21,12 @@ export default class LoggerFactory { return logger; } + public static setLoggingLevel(level: LoggingLevelType): void { + const loggingLevel = LoggingLevelMapping.convertLoggingLevelTypeToLoggingLevel(level); + console.log(`${new Date().toISOString()} [LoggerFactory] Setting logging level to [${level}]`); + LoggerFactory._threshold.level = loggingLevel; + } + private constructor() { throw new Error('[LoggerFactory] is a static class that may not be instantiated'); } diff --git a/test/logger/LoggingLevel.ts b/test/logger/LoggingLevel.ts index 566777e..464f30f 100644 --- a/test/logger/LoggingLevel.ts +++ b/test/logger/LoggingLevel.ts @@ -37,21 +37,21 @@ export class LoggingLevelMapping { public static convertLoggingLevelTypeToLoggingLevel(level: LoggingLevelType): LoggingLevel { switch (level) { - case 'Off': + case 'off': return LoggingLevel.Off; - case 'Fatal': + case 'fatal': return LoggingLevel.Fatal; - case 'Error': + case 'error': return LoggingLevel.Error; - case 'Warning': + case 'warning': return LoggingLevel.Warning; - case 'Info': + case 'info': return LoggingLevel.Info; - case 'Debug': + case 'debug': return LoggingLevel.Debug; - case 'Trace': + case 'trace': return LoggingLevel.Trace; - case 'All': + case 'all': return LoggingLevel.All; default: throw new Error(`[LoggingLevelMapping] Received unknown logging level type [${level}]`); diff --git a/test/logger/Threshold.ts b/test/logger/Threshold.ts index c3b8692..3ef8047 100644 --- a/test/logger/Threshold.ts +++ b/test/logger/Threshold.ts @@ -1,4 +1,4 @@ -import {LoggingLevel, LoggingLevelMapping, type LoggingLevelType} from './LoggingLevel'; +import {LoggingLevel} from './LoggingLevel'; export class Threshold { private readonly _level: {value: LoggingLevel}; diff --git a/test/runner/TestRunner.ts b/test/runner/TestRunner.ts index 314301b..1f7a736 100644 --- a/test/runner/TestRunner.ts +++ b/test/runner/TestRunner.ts @@ -1,25 +1,19 @@ -import PCastAPI from '@techniker-me/pcast-api'; -import RtmpPush from '@technniker-me/rtmp-push'; +import LoggerFactory from '../logger/LoggerFactory'; import CommandLine from '../config/CommandLine'; +import { CommandLineOptions } from '../config/CommandLine'; -interface CommandLineOptions { - applicationId: string; - secret: string; - logLevel: string; -} - -class TestRunner { +export default class TestRunner { + private static readonly _logger = LoggerFactory.getLogger('TestRunner'); private static readonly _commandLineOptions: CommandLineOptions = CommandLine.parse(process.argv); - public static main(): void { - const testRunner = new TestRunner(); - testRunner.run(); + static { + TestRunner.run(); } - public run(): void { - console.log(TestRunner._commandLineOptions); + public static run(): void { + LoggerFactory.setLoggingLevel(TestRunner._commandLineOptions.logLevel); + + TestRunner._logger.info('TestRunner started'); + TestRunner._logger.info(JSON.stringify(TestRunner._commandLineOptions, null, 2)); } -} - -TestRunner.main(); - +} \ No newline at end of file