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

Commit a54c0e0

Browse files
Derek Cliffordsjelin
Derek Clifford
authored andcommitted
feat(plugins): Add config option to disable logging of warnings in console 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.
1 parent 645133d commit a54c0e0

File tree

5 files changed

+52
-10
lines changed

5 files changed

+52
-10
lines changed

docs/plugins.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -408,14 +408,15 @@ This plugin checks the browser log after each test for warnings and errors. It
408408
can be configured to fail a test if either is detected. There is also an
409409
optional exclude parameter which accepts both regex and strings. Any log
410410
matching the exclude parameter will not fail the test or be logged to the
411-
console.
411+
console. A false setting to logWarnings also overrides the failOnWarning setting.
412412

413413
```js
414414
exports.config = {
415415
plugins: [{
416416
path: 'node_modules/protractor/plugins/console',
417417
failOnWarning: {Boolean} (Default - false),
418-
failOnError: {Boolean} (Default - true)
418+
failOnError: {Boolean} (Default - true),
419+
logWarnings: {Boolean} (Default - true),
419420
exclude: {Array of strings and regex} (Default - [])
420421
}]
421422
};

plugins/console/index.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ var q = require('q');
55
* It can be configured to fail a test if either is detected. There is also an
66
* optional exclude parameter which accepts both regex and strings. Any log
77
* matching the exclude parameter will not fail the test or be logged to the
8-
* console.
8+
* console. A false setting to logWarnings also overrides the failOnWarning setting.
99
*
1010
* exports.config = {
1111
* plugins: [{
1212
* path: 'node_modules/protractor/plugins/console',
1313
* failOnWarning: {Boolean} (Default - false),
14-
* failOnError: {Boolean} (Default - true)
14+
* failOnError: {Boolean} (Default - true),
15+
* logWarnings: {Boolean} (Default - true),
1516
* exclude: {Array of strings and regex} (Default - [])
1617
* }]
1718
* };
@@ -76,14 +77,18 @@ ConsolePlugin.parseLog = function(context) {
7677
context.config.failOnWarning;
7778
var failOnError = (context.config.failOnError === undefined) ? true :
7879
context.config.failOnError;
80+
var logWarnings = (context.config.logWarnings === undefined) ? true :
81+
context.config.logWarnings;
7982
ConsolePlugin.exclude = context.config.exclude || [];
8083

8184
return ConsolePlugin.getBrowserLog().then(function(log) {
82-
83-
var warnings = log.filter(function(node) {
84-
return (node.level || {}).name === 'WARNING' &&
85-
ConsolePlugin.includeLog(node.message);
86-
});
85+
var warnings = [];
86+
if (logWarnings) {
87+
warnings = log.filter(function(node) {
88+
return (node.level || {}).name === 'WARNING' &&
89+
ConsolePlugin.includeLog(node.message);
90+
});
91+
}
8792

8893
var errors = log.filter(function(node) {
8994
return (node.level || {}).name === 'SEVERE' &&
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var env = require('../../../spec/environment.js');
2+
3+
exports.config = {
4+
seleniumAddress: env.seleniumAddress,
5+
framework: 'jasmine2',
6+
specs: ['fail_warning_spec.js'],
7+
baseUrl: env.baseUrl,
8+
plugins: [{
9+
path: '../index.js',
10+
failOnWarning: true,
11+
logWarnings: true,
12+
failOnError: false
13+
}]
14+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var env = require('../../../spec/environment.js');
2+
3+
exports.config = {
4+
seleniumAddress: env.seleniumAddress,
5+
framework: 'jasmine2',
6+
specs: ['pass_spec.js'],
7+
baseUrl: env.baseUrl,
8+
plugins: [{
9+
path: '../index.js',
10+
failOnWarning: true,
11+
logWarnings: false,
12+
failOnError: false
13+
}]
14+
};

scripts/test.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ passingTests.push(
4646
'node lib/cli.js plugins/timeline/spec/conf.js',
4747
'node lib/cli.js plugins/ngHint/spec/successConfig.js',
4848
'node lib/cli.js plugins/accessibility/spec/successConfig.js',
49-
'node lib/cli.js plugins/console/spec/consolePassConfig.js'
49+
'node lib/cli.js plugins/console/spec/consolePassConfig.js',
50+
'node lib/cli.js plugins/console/spec/consolePassLogWarnings.js'
5051
);
5152

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

195+
executor.addCommandlineTest(
196+
'node lib/cli.js plugins/console/spec/consoleFailLogWarnings.js')
197+
.expectExitCode(1)
198+
.expectErrors([
199+
{message: 'This is a test warning'}
200+
]);
201+
194202
executor.execute();

0 commit comments

Comments
 (0)