Permalink
Browse files

Report diff image in HTML

  • Loading branch information...
1 parent d66eede commit e1a8b10ff6166373a4634e5b1663f25f792d750b Sergey Tatarintsev committed Feb 14, 2014
Showing with 24 additions and 11 deletions.
  1. +8 −7 lib/image.js
  2. +7 −0 lib/reporters/html-tpl.html
  3. +9 −4 lib/reporters/html.js
View
@@ -4,6 +4,8 @@ var q = require('q'),
gm = require('gm'),
inherit = require('inherit');
+var gmCompare = q.denodeify(gm.compare.bind(gm));
+
module.exports = inherit({
__constructor: function(buffer) {
this._gm = gm(buffer);
@@ -26,13 +28,12 @@ module.exports = inherit({
}
}, {
compare: function(path1, path2) {
- var d = q.defer();
- gm.compare(path1, path2, 0.001, function(error, isEqual) {
- if (error) {
- return d.reject(error);
- }
- d.resolve(isEqual);
+ return gmCompare(path1, path2, 0.001).spread(function(equal) {
+ return equal;
});
- return d.promise;
+ },
+
+ buildDiff: function(ref, image, diff) {
+ return gmCompare(ref, image, {file: diff});
}
});
@@ -44,6 +44,13 @@ <h3 class="<%= test.equal? 'success' : 'fail' %>"><%- test.state %></h3>
<div>Current</div>
<img class="current-image" src="<%= attach(plan.name, test.state, 'current') %>">
</div>
+
+
+ <div class="image-box">
+ <div>Diff</div>
+ <img class="ref-image" src="<%= attach(plan.name, test.state, 'diff') %>">
+ </div>
+
<%} %>
<%});%>
<% });%>
View
@@ -1,9 +1,9 @@
'use strict';
-var q = require('q'),
- fs = require('q-io/fs'),
+var fs = require('q-io/fs'),
path = require('path'),
- _ = require('lodash');
+ _ = require('lodash'),
+ Image = require('../image');
var REPORT_DIR = 'shooter-report',
REPORT_INDEX = path.join(REPORT_DIR, 'index.html'),
@@ -36,6 +36,7 @@ module.exports = function htmlReporter(tester) {
});
tester.on('endTest', function(result) {
+ result.diffPath = attachmentPath(result.name, result.state, 'diff');
currentPlan.tests.push(result);
attachmentsQueue.then(function() {
var copyCurrent = fs.copy(result.currentPath, attachmentPath(result.name, result.state, 'current'));
@@ -45,7 +46,11 @@ module.exports = function htmlReporter(tester) {
return copyCurrent
.then(function() {
return fs.copy(result.previousPath, attachmentPath(result.name, result.state, 'ref'));
- });
+ })
+ .then(function() {
+ return Image.buildDiff(result.previousPath, result.currentPath, result.diffPath);
+ })
+ .done();
});
});

0 comments on commit e1a8b10

Please sign in to comment.