Skip to content

Commit 33e3f3e

Browse files
corinna000alexeagle
authored andcommitted
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
1 parent 1b929af commit 33e3f3e

File tree

1 file changed

+22
-15
lines changed
  • packages/angular_devkit/build_angular/src/angular-cli-files/plugins

1 file changed

+22
-15
lines changed

packages/angular_devkit/build_angular/src/angular-cli-files/plugins/karma.ts

+22-15
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,29 @@ function requestBlocker() {
229229
};
230230
}
231231

232+
// Copied from "karma-jasmine-diff-reporter" source code:
233+
// In case, when multiple reporters are used in conjunction
234+
// with initSourcemapReporter, they both will show repetitive log
235+
// messages when displaying everything that supposed to write to terminal.
236+
// So just suppress any logs from initSourcemapReporter by doing nothing on
237+
// browser log, because it is an utility reporter,
238+
// unless it's alone in the "reporters" option and base reporter is used.
239+
function muteDuplicateReporterLogging(context: any, config: any) {
240+
context.writeCommonMsg = function () { };
241+
const reporterName = '@angular/cli';
242+
const hasTrailingReporters = config.reporters.slice(-1).pop() !== reporterName;
243+
244+
if (hasTrailingReporters) {
245+
context.writeCommonMsg = function () { };
246+
}
247+
}
248+
232249
// Emits builder events.
233-
const eventReporter: any = function (this: any, baseReporterDecorator: any) {
250+
const eventReporter: any = function (this: any, baseReporterDecorator: any, config: any) {
234251
baseReporterDecorator(this);
235252

253+
muteDuplicateReporterLogging(this, config);
254+
236255
this.onRunComplete = function (_browsers: any, results: any) {
237256
if (results.exitCode === 0) {
238257
successCb && successCb();
@@ -242,25 +261,13 @@ const eventReporter: any = function (this: any, baseReporterDecorator: any) {
242261
}
243262
};
244263

245-
eventReporter.$inject = ['baseReporterDecorator'];
264+
eventReporter.$inject = ['baseReporterDecorator', 'config'];
246265

247266
// Strip the server address and webpack scheme (webpack://) from error log.
248267
const sourceMapReporter: any = function (this: any, baseReporterDecorator: any, config: any) {
249268
baseReporterDecorator(this);
250269

251-
const reporterName = '@angular/cli';
252-
const hasTrailingReporters = config.reporters.slice(-1).pop() !== reporterName;
253-
254-
// Copied from "karma-jasmine-diff-reporter" source code:
255-
// In case, when multiple reporters are used in conjunction
256-
// with initSourcemapReporter, they both will show repetitive log
257-
// messages when displaying everything that supposed to write to terminal.
258-
// So just suppress any logs from initSourcemapReporter by doing nothing on
259-
// browser log, because it is an utility reporter,
260-
// unless it's alone in the "reporters" option and base reporter is used.
261-
if (hasTrailingReporters) {
262-
this.writeCommonMsg = function () { };
263-
}
270+
muteDuplicateReporterLogging(this, config);
264271

265272
const urlRegexp = /\(http:\/\/localhost:\d+\/_karma_webpack_\/webpack:\//gi;
266273

0 commit comments

Comments
 (0)