Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Add basic html reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Tatarintsev committed Feb 13, 2014
1 parent 8f8da7d commit d66eede
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 1 deletion.
51 changes: 51 additions & 0 deletions 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>
73 changes: 73 additions & 0 deletions 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);
});
});
};
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -14,7 +14,8 @@
"q": "~1.0.0", "q": "~1.0.0",
"q-io": "~1.10.8", "q-io": "~1.10.8",
"chalk": "~0.4.0", "chalk": "~0.4.0",
"temp": "~0.6.0" "temp": "~0.6.0",
"lodash": "~2.4.1"
}, },
"devDependencies": {}, "devDependencies": {},
"scripts": { "scripts": {
Expand Down

0 comments on commit d66eede

Please sign in to comment.