Permalink
Browse files

Add basic html reporter

  • Loading branch information...
1 parent 8f8da7d commit d66eede12881a25cda511fb43daa3fe1b764d02f Sergey Tatarintsev committed Feb 13, 2014
Showing with 126 additions and 1 deletion.
  1. +51 −0 lib/reporters/html-tpl.html
  2. +73 −0 lib/reporters/html.js
  3. +2 −1 package.json
View
51 lib/reporters/html-tpl.html
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Shooter report</title>
+ <style>
+ .success::before {
+ content: '\2713 ';
+ color: green;
+ }
+
+ .fail {
+ color: red;
+ }
+
+ .fail:before {
+ content: '\2718 ';
+ color: red;
+ }
+
+ .image-box {
+ display: inline-block;
+ padding: 5px;
+ }
+
+ </style>
+ </head>
+
+ <body>
+ <h1>Shooter report</h1>
+ <% plans.forEach(function(plan) { %>
+ <h2><%- plan.name %></h2>
+ <% plan.tests.forEach(function(test) { %>
+ <h3 class="<%= test.equal? 'success' : 'fail' %>"><%- test.state %></h3>
+ <% if (test.equal) { %>
+ <img src="<%= attach(plan.name, test.state, 'current') %>">
+ <%} else {%>
+ <div class="image-box">
+ <div>Reference</div>
+ <img class="ref-image" src="<%= attach(plan.name, test.state, 'ref') %>">
+ </div>
+
+
+ <div class="image-box">
+ <div>Current</div>
+ <img class="current-image" src="<%= attach(plan.name, test.state, 'current') %>">
+ </div>
+ <%} %>
+ <%});%>
+ <% });%>
+ </body>
+</html>
View
73 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);
+ });
+ });
+};
View
3 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": {

0 comments on commit d66eede

Please sign in to comment.