Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support debug logging (#1150) #1207

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/executors/Browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default class Browser extends Executor<Events, Config, Plugins> {
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) {
Expand Down
15 changes: 14 additions & 1 deletion src/lib/reporters/Console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

Expand All @@ -22,6 +28,13 @@ export default class ConsoleReporter extends Reporter {
this.console.error(this.formatError(error));
}

@eventHandler()
log(data: any) {
if (this._debugLogs) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reporter doesn't actually need to check any sort of debug condition. Other parts of Intern handle that (see log in src/lib/executors/Executor.ts), so the Console reporter should simply need to implement a handler for the log event.

this.console.log(data);
}
}

@eventHandler()
suiteEnd(suite: Suite) {
// IE<10 does not provide a global console object when Developer Tools
Expand Down