Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
feat(plugins): Add config option to disable logging of warnings in co…
Browse files Browse the repository at this point in the history
…nsole plugin

Running tests in multiple browsers ends up printing out a lot of useless warnings I'm already aware of. To make skimming through logs in the case of an actual failure easier, I want to be able to disable the logging of warnings in the console plugin.
  • Loading branch information
Derek Clifford authored and sjelin committed Oct 26, 2015
1 parent 645133d commit a54c0e0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 10 deletions.
5 changes: 3 additions & 2 deletions docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,14 +408,15 @@ This plugin checks the browser log after each test for warnings and errors. It
can be configured to fail a test if either is detected. There is also an
optional exclude parameter which accepts both regex and strings. Any log
matching the exclude parameter will not fail the test or be logged to the
console.
console. A false setting to logWarnings also overrides the failOnWarning setting.

```js
exports.config = {
plugins: [{
path: 'node_modules/protractor/plugins/console',
failOnWarning: {Boolean} (Default - false),
failOnError: {Boolean} (Default - true)
failOnError: {Boolean} (Default - true),
logWarnings: {Boolean} (Default - true),
exclude: {Array of strings and regex} (Default - [])
}]
};
Expand Down
19 changes: 12 additions & 7 deletions plugins/console/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ var q = require('q');
* It can be configured to fail a test if either is detected. There is also an
* optional exclude parameter which accepts both regex and strings. Any log
* matching the exclude parameter will not fail the test or be logged to the
* console.
* console. A false setting to logWarnings also overrides the failOnWarning setting.
*
* exports.config = {
* plugins: [{
* path: 'node_modules/protractor/plugins/console',
* failOnWarning: {Boolean} (Default - false),
* failOnError: {Boolean} (Default - true)
* failOnError: {Boolean} (Default - true),
* logWarnings: {Boolean} (Default - true),
* exclude: {Array of strings and regex} (Default - [])
* }]
* };
Expand Down Expand Up @@ -76,14 +77,18 @@ ConsolePlugin.parseLog = function(context) {
context.config.failOnWarning;
var failOnError = (context.config.failOnError === undefined) ? true :
context.config.failOnError;
var logWarnings = (context.config.logWarnings === undefined) ? true :
context.config.logWarnings;
ConsolePlugin.exclude = context.config.exclude || [];

return ConsolePlugin.getBrowserLog().then(function(log) {

var warnings = log.filter(function(node) {
return (node.level || {}).name === 'WARNING' &&
ConsolePlugin.includeLog(node.message);
});
var warnings = [];
if (logWarnings) {
warnings = log.filter(function(node) {
return (node.level || {}).name === 'WARNING' &&
ConsolePlugin.includeLog(node.message);
});
}

var errors = log.filter(function(node) {
return (node.level || {}).name === 'SEVERE' &&
Expand Down
14 changes: 14 additions & 0 deletions plugins/console/spec/consoleFailLogWarnings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var env = require('../../../spec/environment.js');

exports.config = {
seleniumAddress: env.seleniumAddress,
framework: 'jasmine2',
specs: ['fail_warning_spec.js'],
baseUrl: env.baseUrl,
plugins: [{
path: '../index.js',
failOnWarning: true,
logWarnings: true,
failOnError: false
}]
};
14 changes: 14 additions & 0 deletions plugins/console/spec/consolePassLogWarnings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var env = require('../../../spec/environment.js');

exports.config = {
seleniumAddress: env.seleniumAddress,
framework: 'jasmine2',
specs: ['pass_spec.js'],
baseUrl: env.baseUrl,
plugins: [{
path: '../index.js',
failOnWarning: true,
logWarnings: false,
failOnError: false
}]
};
10 changes: 9 additions & 1 deletion scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ passingTests.push(
'node lib/cli.js plugins/timeline/spec/conf.js',
'node lib/cli.js plugins/ngHint/spec/successConfig.js',
'node lib/cli.js plugins/accessibility/spec/successConfig.js',
'node lib/cli.js plugins/console/spec/consolePassConfig.js'
'node lib/cli.js plugins/console/spec/consolePassConfig.js',
'node lib/cli.js plugins/console/spec/consolePassLogWarnings.js'
);

var executor = new Executor();
Expand Down Expand Up @@ -191,4 +192,11 @@ executor.addCommandlineTest(
{message: 'This is a test error'}
]);

executor.addCommandlineTest(
'node lib/cli.js plugins/console/spec/consoleFailLogWarnings.js')
.expectExitCode(1)
.expectErrors([
{message: 'This is a test warning'}
]);

executor.execute();

0 comments on commit a54c0e0

Please sign in to comment.