Skip to content

Commit f46869d

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 ffdbb0a commit f46869d

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();
@@ -245,25 +264,13 @@ const eventReporter: any = function (this: any, baseReporterDecorator: any) {
245264
this.specFailure = () => {};
246265
};
247266

248-
eventReporter.$inject = ['baseReporterDecorator'];
267+
eventReporter.$inject = ['baseReporterDecorator', 'config'];
249268

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

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

268275
const urlRegexp = /\(http:\/\/localhost:\d+\/_karma_webpack_\/webpack:\//gi;
269276

0 commit comments

Comments
 (0)