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

Commit 997937d

Browse files
el-davosjelin
authored andcommitted
feat(console plugin): Added new console plugin
1 parent ef6a09d commit 997937d

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ testapp/inbrowsertest/
44
website/bower_components/
55
website/build/
66
website/docgen/build/
7+
.idea
78

89
chromedriver.log
910
libpeerconnection.log
1011
changes.sh
1112
xmloutput*
1213
npm-debug.log
1314

14-
*.swp
15+
*.swp

plugins/console/index.js

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
var q = require('q');
2+
3+
var testOut = {failedCount: 0, specResults: []};
4+
5+
var ConsolePlugin = function () {
6+
this.failOnWarning = false;
7+
this.failOnError = true;
8+
};
9+
10+
ConsolePlugin.getBrowserLog = function () {
11+
return browser.manage().logs().get('browser');
12+
};
13+
14+
ConsolePlugin.logMessages = function (warnings, errors) {
15+
warnings.map(function (warning) {
16+
console.error(warning.level.name + ': ' + warning.message);
17+
});
18+
19+
errors.map(function (error) {
20+
console.error(error.level.name + ': ' + error.message);
21+
});
22+
};
23+
24+
ConsolePlugin.parseLog = function (config) {
25+
var self = this;
26+
var deferred = q.defer();
27+
var failOnWarning = config.failOnWarning || this.failOnWarning;
28+
var failOnError = config.failOnError || this.failOnError;
29+
this.getBrowserLog().then(function (log) {
30+
31+
var warnings = log.filter(function (node) {
32+
return (node.level || {}).name === 'WARNING';
33+
});
34+
35+
var errors = log.filter(function (node) {
36+
return (node.level || {}).name === 'SEVERE';
37+
});
38+
39+
if (warnings.length > 0 || errors.length > 0) {
40+
self.logMessages(warnings, errors);
41+
}
42+
43+
testOut.failedCount += (warnings.length > 0 && failOnWarning) ? 1 : 0;
44+
testOut.failedCount += (errors.length > 0 && failOnError) ? 1 : 0;
45+
46+
deferred.resolve();
47+
});
48+
49+
return deferred.promise;
50+
};
51+
52+
ConsolePlugin.prototype.postTest = function (config, passed) {
53+
54+
};
55+
56+
ConsolePlugin.prototype.teardown = function (config) {
57+
var audits = [];
58+
59+
audits.push(ConsolePlugin.parseLog(config));
60+
61+
return q.all(audits).then(function (result) {
62+
return testOut;
63+
});
64+
};
65+
66+
ConsolePlugin.prototype.postResults = function (config) {
67+
68+
};
69+
70+
var consolePlugin = new ConsolePlugin();
71+
72+
exports.teardown = consolePlugin.teardown.bind(consolePlugin);
73+
exports.postResults = consolePlugin.postResults.bind(consolePlugin);
74+
exports.postTest = consolePlugin.postTest.bind(consolePlugin);
75+
76+
exports.ConsolePlugin = ConsolePlugin;
77+
78+
exports.name = '';

0 commit comments

Comments
 (0)