From 52b51516cd4535907350ae885b279b987eb1d6cc Mon Sep 17 00:00:00 2001 From: Oleg Gomozov Date: Tue, 17 Jan 2017 15:11:42 -0800 Subject: [PATCH 1/7] filter browser logging by level of LOG Additional fix to the next bug: filter browser logging by level ([35965d9](https://github.com/karma-runner/karma/commit/35965d9)), closes [#2228](https://github.com/karma-runner/karma/issues/2228) otherwise console.log ignore doesn't work with browserConsoleLogOptions: { level: 'debug', terminal: true } --- lib/constants.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/constants.js b/lib/constants.js index 11b5e3ad3..15da4dc0d 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -15,13 +15,14 @@ exports.LOG_ERROR = 'ERROR' exports.LOG_WARN = 'WARN' exports.LOG_INFO = 'INFO' exports.LOG_DEBUG = 'DEBUG' +exports.LOG_LOG = 'LOG' exports.LOG_PRIORITIES = [ exports.LOG_DISABLE, exports.LOG_ERROR, exports.LOG_WARN, exports.LOG_INFO, exports.LOG_DEBUG, - exports.LOG_DISABLE + exports.LOG_LOG ] // Default patterns for the pattern layout. From eae0766a9fd50ab085dcadc61ac341c6fb2e23ca Mon Sep 17 00:00:00 2001 From: Oleg Gomozov Date: Wed, 18 Jan 2017 11:27:03 -0800 Subject: [PATCH 2/7] unit tests for browserConsoleLogOptions --- test/unit/reporters/base.spec.js | 40 ++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/test/unit/reporters/base.spec.js b/test/unit/reporters/base.spec.js index a0c31477b..65b3d25ab 100644 --- a/test/unit/reporters/base.spec.js +++ b/test/unit/reporters/base.spec.js @@ -83,9 +83,45 @@ describe('reporter', function () { return expect(writeSpy).to.have.been.calledWith('LOG: Message\n') }) - it('should not log if lower priority than browserConsoleLogOptions.level', function () { + it('should not log if lower priority than browserConsoleLogOptions "error"', function () { var reporter = new m.BaseReporter(null, null, true, { - browserConsoleLogOptions: {level: 'ERROR'} + browserConsoleLogOptions: {level: 'error'} + }, adapter) + var writeSpy = sinon.spy(reporter, 'writeCommonMsg') + + reporter._browsers = ['Chrome'] + reporter.onBrowserLog('Chrome', 'Message', 'WARN') + + return writeSpy.should.have.not.been.called + }) + + it('should not log if lower priority than browserConsoleLogOptions "warn"', function () { + var reporter = new m.BaseReporter(null, null, true, { + browserConsoleLogOptions: {level: 'warn'} + }, adapter) + var writeSpy = sinon.spy(reporter, 'writeCommonMsg') + + reporter._browsers = ['Chrome'] + reporter.onBrowserLog('Chrome', 'Message', 'INFO') + + return writeSpy.should.have.not.been.called + }) + + it('should not log if lower priority than browserConsoleLogOptions "info"', function () { + var reporter = new m.BaseReporter(null, null, true, { + browserConsoleLogOptions: {level: 'info'} + }, adapter) + var writeSpy = sinon.spy(reporter, 'writeCommonMsg') + + reporter._browsers = ['Chrome'] + reporter.onBrowserLog('Chrome', 'Message', 'DEBUG') + + return writeSpy.should.have.not.been.called + }) + + it('should not log if lower priority than browserConsoleLogOptions "debug"', function () { + var reporter = new m.BaseReporter(null, null, true, { + browserConsoleLogOptions: {level: 'debug'} }, adapter) var writeSpy = sinon.spy(reporter, 'writeCommonMsg') From 83c60139ef7c4657525e624bace05d0754e0e439 Mon Sep 17 00:00:00 2001 From: Oleg Gomozov Date: Wed, 18 Jan 2017 11:59:42 -0800 Subject: [PATCH 3/7] remove trailing spaces --- test/unit/reporters/base.spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unit/reporters/base.spec.js b/test/unit/reporters/base.spec.js index 65b3d25ab..2cb49372b 100644 --- a/test/unit/reporters/base.spec.js +++ b/test/unit/reporters/base.spec.js @@ -94,7 +94,7 @@ describe('reporter', function () { return writeSpy.should.have.not.been.called }) - + it('should not log if lower priority than browserConsoleLogOptions "warn"', function () { var reporter = new m.BaseReporter(null, null, true, { browserConsoleLogOptions: {level: 'warn'} @@ -106,7 +106,7 @@ describe('reporter', function () { return writeSpy.should.have.not.been.called }) - + it('should not log if lower priority than browserConsoleLogOptions "info"', function () { var reporter = new m.BaseReporter(null, null, true, { browserConsoleLogOptions: {level: 'info'} @@ -117,7 +117,7 @@ describe('reporter', function () { reporter.onBrowserLog('Chrome', 'Message', 'DEBUG') return writeSpy.should.have.not.been.called - }) + }) it('should not log if lower priority than browserConsoleLogOptions "debug"', function () { var reporter = new m.BaseReporter(null, null, true, { From 0c4c67b1d3ed99c3e024a4e2b5c7d0dffda39ffe Mon Sep 17 00:00:00 2001 From: Oleg Gomozov Date: Wed, 18 Jan 2017 12:54:57 -0800 Subject: [PATCH 4/7] change default browserConsoleLogOptions to log --- lib/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config.js b/lib/config.js index 089125bcf..ebae39b5f 100644 --- a/lib/config.js +++ b/lib/config.js @@ -286,7 +286,7 @@ var Config = function () { this.basePath = '' this.files = [] this.browserConsoleLogOptions = { - level: 'debug', + level: 'log', format: '%b %T: %m', terminal: true } From 4a44cf1b0db08e8816ab1a510a364a088a690423 Mon Sep 17 00:00:00 2001 From: Oleg Gomozov Date: Wed, 18 Jan 2017 13:06:11 -0800 Subject: [PATCH 5/7] change level to log to support integration tests --- test/e2e/browser_console.feature | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/e2e/browser_console.feature b/test/e2e/browser_console.feature index 143930918..9a25f5cc5 100644 --- a/test/e2e/browser_console.feature +++ b/test/e2e/browser_console.feature @@ -11,7 +11,10 @@ Feature: Browser Console Configuration plugins = [ 'karma-jasmine', 'karma-phantomjs-launcher' - ]; + ], + browserConsoleLogOptions = { + level: 'log' + }; """ When I start Karma Then it passes with like: From 51d451bfb07f5a2e78a37c387c9be240c2791f27 Mon Sep 17 00:00:00 2001 From: Oleg Gomozov Date: Wed, 18 Jan 2017 13:13:59 -0800 Subject: [PATCH 6/7] change level to log to support integration tests --- test/e2e/browser_console.feature | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/e2e/browser_console.feature b/test/e2e/browser_console.feature index 9a25f5cc5..de81b4eec 100644 --- a/test/e2e/browser_console.feature +++ b/test/e2e/browser_console.feature @@ -54,7 +54,8 @@ Feature: Browser Console Configuration ]; browserConsoleLogOptions = { path: 'console.log', - format: '%t:%m' + format: '%t:%m', + level: 'log' }; """ When I start Karma @@ -78,7 +79,8 @@ Feature: Browser Console Configuration ]; browserConsoleLogOptions = { path: 'console.log', - format: '%t:%T:%m' + format: '%t:%T:%m', + level: 'log' }; """ When I start Karma From 947235467b4d97a9ec1a99394aa0c18b8b2b0495 Mon Sep 17 00:00:00 2001 From: blackswanny Date: Thu, 19 Jan 2017 16:10:48 -0800 Subject: [PATCH 7/7] fix: add support of browser log to integration tests --- lib/config.js | 2 +- test/e2e/browser_console.feature | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/config.js b/lib/config.js index ebae39b5f..089125bcf 100644 --- a/lib/config.js +++ b/lib/config.js @@ -286,7 +286,7 @@ var Config = function () { this.basePath = '' this.files = [] this.browserConsoleLogOptions = { - level: 'log', + level: 'debug', format: '%b %T: %m', terminal: true } diff --git a/test/e2e/browser_console.feature b/test/e2e/browser_console.feature index de81b4eec..9a25f5cc5 100644 --- a/test/e2e/browser_console.feature +++ b/test/e2e/browser_console.feature @@ -54,8 +54,7 @@ Feature: Browser Console Configuration ]; browserConsoleLogOptions = { path: 'console.log', - format: '%t:%m', - level: 'log' + format: '%t:%m' }; """ When I start Karma @@ -79,8 +78,7 @@ Feature: Browser Console Configuration ]; browserConsoleLogOptions = { path: 'console.log', - format: '%t:%T:%m', - level: 'log' + format: '%t:%T:%m' }; """ When I start Karma