diff --git a/lib/reporters/html-tpl.html b/lib/reporters/html-tpl.html new file mode 100644 index 000000000..297f583a6 --- /dev/null +++ b/lib/reporters/html-tpl.html @@ -0,0 +1,51 @@ + + + + Shooter report + + + + +

Shooter report

+ <% plans.forEach(function(plan) { %> +

<%- plan.name %>

+ <% plan.tests.forEach(function(test) { %> +

<%- test.state %>

+ <% if (test.equal) { %> + + <%} else {%> +
+
Reference
+ +
+ + +
+
Current
+ +
+ <%} %> + <%});%> + <% });%> + + diff --git a/lib/reporters/html.js b/lib/reporters/html.js new file mode 100644 index 000000000..91d72cb34 --- /dev/null +++ b/lib/reporters/html.js @@ -0,0 +1,73 @@ +'use strict'; + +var q = require('q'), + fs = require('q-io/fs'), + path = require('path'), + _ = require('lodash'); + +var REPORT_DIR = 'shooter-report', + REPORT_INDEX = path.join(REPORT_DIR, 'index.html'), + REPORT_ATTACHMENTS = path.join(REPORT_DIR, 'attach'); + +function attachmentsPath(plan) { + return path.join(REPORT_ATTACHMENTS, plan); +} + +function attachmentPath(plan, state, kind) { + return path.join(attachmentsPath(plan), state + '~' + kind + '.png'); +} + +module.exports = function htmlReporter(tester) { + var plans, + currentPlan, + attachmentsQueue; + + tester.on('beginTests', function() { + plans = []; + attachmentsQueue = fs.makeTree(REPORT_ATTACHMENTS); + }); + + tester.on('beginPlan', function(plan) { + currentPlan = {name: plan, tests: []}; + plans.push(currentPlan); + attachmentsQueue.then(function() { + return fs.makeDirectory(attachmentsPath(plan)); + }); + }); + + tester.on('endTest', function(result) { + currentPlan.tests.push(result); + attachmentsQueue.then(function() { + var copyCurrent = fs.copy(result.currentPath, attachmentPath(result.name, result.state, 'current')); + if (result.equal) { + return copyCurrent; + } + return copyCurrent + .then(function() { + return fs.copy(result.previousPath, attachmentPath(result.name, result.state, 'ref')); + }); + }); + }); + + tester.on('endTests', function () { + attachmentsQueue + .then(function() { + return fs.read(path.resolve(__dirname, './html-tpl.html')); + }) + .then(function(tpl) { + var tplFunc = _.template(tpl); + return tplFunc({ + plans: plans, + attach: function(plan, state, kind) { + return encodeURIComponent(path.join('attach', plan, state + '~' + kind + '.png')); + } + }); + }) + .then(function(index) { + return fs.write(REPORT_INDEX, index); + }) + .fail(function(error) { + console.log('err', error); + }); + }); +}; diff --git a/package.json b/package.json index cf2c5b730..a061296ca 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "q": "~1.0.0", "q-io": "~1.10.8", "chalk": "~0.4.0", - "temp": "~0.6.0" + "temp": "~0.6.0", + "lodash": "~2.4.1" }, "devDependencies": {}, "scripts": {