From f46869d4ed94d84a855b5b10f1ff762aaf03c2c9 Mon Sep 17 00:00:00 2001 From: Corinna Cohn Date: Tue, 14 Aug 2018 10:29:40 -0400 Subject: [PATCH] refactor(@angular-devkit/build-angular): mute internal reporters (#11238) * 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 * 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 c410cc5b80..71060d02a5 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 @@ -229,10 +229,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(); @@ -245,25 +264,13 @@ const eventReporter: any = function (this: any, baseReporterDecorator: any) { this.specFailure = () => {}; }; -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;