From 79b0d8cadcecb0b3925edeaaac18ac53699c8f9c Mon Sep 17 00:00:00 2001 From: Corinna Cohn Date: Wed, 13 Jun 2018 23:56:50 -0400 Subject: [PATCH 1/2] refactor(@angular-devkit/build-angular): mute internal reporters when other reporters are configured internal Karma reporters should suppress output when user-defined reporters are configured to prevent extrananeous error reporting for failed tests --- .../src/angular-cli-files/plugins/karma.ts | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/packages/angular_devkit/build_angular/src/angular-cli-files/plugins/karma.ts b/packages/angular_devkit/build_angular/src/angular-cli-files/plugins/karma.ts index a2c238dbd2ee..7990797e02a9 100644 --- a/packages/angular_devkit/build_angular/src/angular-cli-files/plugins/karma.ts +++ b/packages/angular_devkit/build_angular/src/angular-cli-files/plugins/karma.ts @@ -224,10 +224,29 @@ function requestBlocker() { }; } +// Copied from "karma-jasmine-diff-reporter" source code: +// In case, when multiple reporters are used in conjunction +// with initSourcemapReporter, they both will show repetitive log +// messages when displaying everything that supposed to write to terminal. +// So just suppress any logs from initSourcemapReporter by doing nothing on +// browser log, because it is an utility reporter, +// unless it's alone in the "reporters" option and base reporter is used. +function muteDuplicateReporterLogging(context: any, config: any) { + context.writeCommonMsg = function () { }; + const reporterName = '@angular/cli'; + const hasTrailingReporters = config.reporters.slice(-1).pop() !== reporterName; + + if (hasTrailingReporters) { + context.writeCommonMsg = function () { }; + } +} + // Emits builder events. -const eventReporter: any = function (this: any, baseReporterDecorator: any) { +const eventReporter: any = function (this: any, baseReporterDecorator: any, config: any) { baseReporterDecorator(this); + muteDuplicateReporterLogging(this, config); + this.onRunComplete = function (_browsers: any, results: any) { if (results.exitCode === 0) { successCb && successCb(); @@ -237,25 +256,13 @@ const eventReporter: any = function (this: any, baseReporterDecorator: any) { } }; -eventReporter.$inject = ['baseReporterDecorator']; +eventReporter.$inject = ['baseReporterDecorator', 'config']; // Strip the server address and webpack scheme (webpack://) from error log. const sourceMapReporter: any = function (this: any, baseReporterDecorator: any, config: any) { baseReporterDecorator(this); - const reporterName = '@angular/cli'; - const hasTrailingReporters = config.reporters.slice(-1).pop() !== reporterName; - - // Copied from "karma-jasmine-diff-reporter" source code: - // In case, when multiple reporters are used in conjunction - // with initSourcemapReporter, they both will show repetitive log - // messages when displaying everything that supposed to write to terminal. - // So just suppress any logs from initSourcemapReporter by doing nothing on - // browser log, because it is an utility reporter, - // unless it's alone in the "reporters" option and base reporter is used. - if (hasTrailingReporters) { - this.writeCommonMsg = function () { }; - } + muteDuplicateReporterLogging(this, config); const urlRegexp = /\(http:\/\/localhost:\d+\/_karma_webpack_\/webpack:\//gi; From 377a4a7617708538c12248542f870a60c1fac4ec Mon Sep 17 00:00:00 2001 From: Corinna Cohn Date: Wed, 13 Jun 2018 23:56:50 -0400 Subject: [PATCH 2/2] refactor(@angular-devkit/build-angular): mute internal reporters when other reporters are configured internal Karma reporters should suppress output when user-defined reporters are configured to prevent extrananeous error reporting for failed tests --- .../src/angular-cli-files/plugins/karma.ts | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/packages/angular_devkit/build_angular/src/angular-cli-files/plugins/karma.ts b/packages/angular_devkit/build_angular/src/angular-cli-files/plugins/karma.ts index a2c238dbd2ee..7990797e02a9 100644 --- a/packages/angular_devkit/build_angular/src/angular-cli-files/plugins/karma.ts +++ b/packages/angular_devkit/build_angular/src/angular-cli-files/plugins/karma.ts @@ -224,10 +224,29 @@ function requestBlocker() { }; } +// Copied from "karma-jasmine-diff-reporter" source code: +// In case, when multiple reporters are used in conjunction +// with initSourcemapReporter, they both will show repetitive log +// messages when displaying everything that supposed to write to terminal. +// So just suppress any logs from initSourcemapReporter by doing nothing on +// browser log, because it is an utility reporter, +// unless it's alone in the "reporters" option and base reporter is used. +function muteDuplicateReporterLogging(context: any, config: any) { + context.writeCommonMsg = function () { }; + const reporterName = '@angular/cli'; + const hasTrailingReporters = config.reporters.slice(-1).pop() !== reporterName; + + if (hasTrailingReporters) { + context.writeCommonMsg = function () { }; + } +} + // Emits builder events. -const eventReporter: any = function (this: any, baseReporterDecorator: any) { +const eventReporter: any = function (this: any, baseReporterDecorator: any, config: any) { baseReporterDecorator(this); + muteDuplicateReporterLogging(this, config); + this.onRunComplete = function (_browsers: any, results: any) { if (results.exitCode === 0) { successCb && successCb(); @@ -237,25 +256,13 @@ const eventReporter: any = function (this: any, baseReporterDecorator: any) { } }; -eventReporter.$inject = ['baseReporterDecorator']; +eventReporter.$inject = ['baseReporterDecorator', 'config']; // Strip the server address and webpack scheme (webpack://) from error log. const sourceMapReporter: any = function (this: any, baseReporterDecorator: any, config: any) { baseReporterDecorator(this); - const reporterName = '@angular/cli'; - const hasTrailingReporters = config.reporters.slice(-1).pop() !== reporterName; - - // Copied from "karma-jasmine-diff-reporter" source code: - // In case, when multiple reporters are used in conjunction - // with initSourcemapReporter, they both will show repetitive log - // messages when displaying everything that supposed to write to terminal. - // So just suppress any logs from initSourcemapReporter by doing nothing on - // browser log, because it is an utility reporter, - // unless it's alone in the "reporters" option and base reporter is used. - if (hasTrailingReporters) { - this.writeCommonMsg = function () { }; - } + muteDuplicateReporterLogging(this, config); const urlRegexp = /\(http:\/\/localhost:\d+\/_karma_webpack_\/webpack:\//gi;