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;