From f02f07986a9330f68fb89cf19df73228b62f3ff1 Mon Sep 17 00:00:00 2001 From: Abolfazl Ghalandary <79265051+abolfazlghalandary@users.noreply.github.com> Date: Wed, 11 Jan 2023 00:10:35 +0330 Subject: [PATCH] Support debug logging --- src/lib/executors/Browser.ts | 2 +- src/lib/reporters/Console.ts | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/lib/executors/Browser.ts b/src/lib/executors/Browser.ts index cf58e66cf..b5c8d6a5e 100644 --- a/src/lib/executors/Browser.ts +++ b/src/lib/executors/Browser.ts @@ -59,7 +59,7 @@ export default class Browser extends Executor { this.registerReporter('dom', (options) => new Dom(this, options)); this.registerReporter( 'console', - (options) => new ConsoleReporter(this, options) + (options) => new ConsoleReporter(this, options, this.config.debug) ); if (options) { diff --git a/src/lib/reporters/Console.ts b/src/lib/reporters/Console.ts index fa8030397..e9ed3095c 100644 --- a/src/lib/reporters/Console.ts +++ b/src/lib/reporters/Console.ts @@ -8,11 +8,17 @@ import Reporter, { eventHandler, ReporterOptions } from './Reporter'; */ export default class ConsoleReporter extends Reporter { private _hasGrouping: boolean; + private _debugLogs: boolean; private _testId: keyof Test; - constructor(executor: Executor, options: ReporterOptions = {}) { + constructor( + executor: Executor, + options: ReporterOptions = {}, + debugLogs: boolean = false + ) { super(executor, options); this._hasGrouping = 'group' in this.console && 'groupEnd' in this.console; + this._debugLogs = debugLogs; this._testId = this._hasGrouping ? 'name' : 'id'; } @@ -22,6 +28,13 @@ export default class ConsoleReporter extends Reporter { this.console.error(this.formatError(error)); } + @eventHandler() + log(data: any) { + if (this._debugLogs) { + this.console.log(data); + } + } + @eventHandler() suiteEnd(suite: Suite) { // IE<10 does not provide a global console object when Developer Tools