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

Commit

Permalink
feat(console plugin): Added new console plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
el-davo authored and sjelin committed Mar 16, 2015
1 parent ef6a09d commit 997937d
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ testapp/inbrowsertest/
website/bower_components/
website/build/
website/docgen/build/
.idea

chromedriver.log
libpeerconnection.log
changes.sh
xmloutput*
npm-debug.log

*.swp
*.swp
78 changes: 78 additions & 0 deletions plugins/console/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
var q = require('q');

var testOut = {failedCount: 0, specResults: []};

var ConsolePlugin = function () {
this.failOnWarning = false;
this.failOnError = true;
};

ConsolePlugin.getBrowserLog = function () {
return browser.manage().logs().get('browser');
};

ConsolePlugin.logMessages = function (warnings, errors) {
warnings.map(function (warning) {
console.error(warning.level.name + ': ' + warning.message);
});

errors.map(function (error) {
console.error(error.level.name + ': ' + error.message);
});
};

ConsolePlugin.parseLog = function (config) {
var self = this;
var deferred = q.defer();
var failOnWarning = config.failOnWarning || this.failOnWarning;
var failOnError = config.failOnError || this.failOnError;
this.getBrowserLog().then(function (log) {

var warnings = log.filter(function (node) {
return (node.level || {}).name === 'WARNING';
});

var errors = log.filter(function (node) {
return (node.level || {}).name === 'SEVERE';
});

if (warnings.length > 0 || errors.length > 0) {
self.logMessages(warnings, errors);
}

testOut.failedCount += (warnings.length > 0 && failOnWarning) ? 1 : 0;
testOut.failedCount += (errors.length > 0 && failOnError) ? 1 : 0;

deferred.resolve();
});

return deferred.promise;
};

ConsolePlugin.prototype.postTest = function (config, passed) {

};

ConsolePlugin.prototype.teardown = function (config) {
var audits = [];

audits.push(ConsolePlugin.parseLog(config));

return q.all(audits).then(function (result) {
return testOut;
});
};

ConsolePlugin.prototype.postResults = function (config) {

};

var consolePlugin = new ConsolePlugin();

exports.teardown = consolePlugin.teardown.bind(consolePlugin);
exports.postResults = consolePlugin.postResults.bind(consolePlugin);
exports.postTest = consolePlugin.postTest.bind(consolePlugin);

exports.ConsolePlugin = ConsolePlugin;

exports.name = '';

0 comments on commit 997937d

Please sign in to comment.