Skip to content

Commit 33ff37a

Browse files
shairezBrocco
authored andcommitted
fix(@angular/cli): remove double console logs with different reporters
see the issue for details closes #9528
1 parent 0a35e5a commit 33ff37a

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

Diff for: packages/@angular/cli/plugins/karma.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,23 @@ function requestBlocker() {
247247
}
248248

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

254269
this.onSpecComplete = function (_browser: any, result: any) {
@@ -260,7 +275,7 @@ const initSourcemapReporter: any = function (this: any, baseReporterDecorator: a
260275
};
261276
};
262277

263-
initSourcemapReporter.$inject = ['baseReporterDecorator'];
278+
initSourcemapReporter.$inject = ['baseReporterDecorator', 'config'];
264279

265280
module.exports = Object.assign({
266281
'framework:@angular/cli': ['factory', init],

0 commit comments

Comments
 (0)