From 997937d189fb3a9fb51f1b2e4756981c8958ceba Mon Sep 17 00:00:00 2001 From: David Ahern Date: Fri, 6 Mar 2015 08:25:13 +0000 Subject: [PATCH] feat(console plugin): Added new console plugin --- .gitignore | 3 +- plugins/console/index.js | 78 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 plugins/console/index.js diff --git a/.gitignore b/.gitignore index 3c28a855a..8eca4ab4e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ testapp/inbrowsertest/ website/bower_components/ website/build/ website/docgen/build/ +.idea chromedriver.log libpeerconnection.log @@ -11,4 +12,4 @@ changes.sh xmloutput* npm-debug.log -*.swp +*.swp \ No newline at end of file diff --git a/plugins/console/index.js b/plugins/console/index.js new file mode 100644 index 000000000..f61537dd8 --- /dev/null +++ b/plugins/console/index.js @@ -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 = ''; \ No newline at end of file