Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the jasmine matcher syntax to more recent standards. #59

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions imagediff.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
var root = this;
if (typeof module !== 'undefined') {
try {
var Canvas = require('canvas');
var Canvas = require('canvas-prebuilt');
} catch (e) {
throw new Error(
e.message + '\n' +
Expand Down Expand Up @@ -365,19 +365,16 @@
isImageType : isImageType,

toImageData : function (object) {
checkType(object);
if (isImageData(object)) { return copyImageData(object); }
return toImageData(object);
},

equal : function (a, b, tolerance) {
checkType(a, b);
a = toImageData(a);
b = toImageData(b);
return equal(a, b, tolerance);
},
diff : function (a, b, options) {
checkType(a, b);
a = toImageData(a);
b = toImageData(b);
return diff(a, b, options);
Expand Down
89 changes: 47 additions & 42 deletions js/imagediff.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
if (typeof module !== 'undefined') {
var Canvas;
try {
Canvas = require('canvas');
Canvas = require('canvas-prebuilt');
} catch (e) {}
module.exports = definition(root, name, Canvas);
} else if (typeof define === 'function' && typeof define.amd === 'object') {
Expand Down Expand Up @@ -281,49 +281,54 @@
jasmine = {

toBeImageData : function () {
return imagediff.isImageData(this.actual);
return {
compare: function (actual) {
return {
pass: imagediff.isImageData(actual)
};
}
};
},

toImageDiffEqual : function (expected, tolerance) {

if (typeof (document) !== UNDEFINED) {
this.message = function () {
var
div = get('div'),
a = get('div', '<div>Actual:</div>'),
b = get('div', '<div>Expected:</div>'),
c = get('div', '<div>Diff:</div>'),
diff = imagediff.diff(this.actual, expected),
canvas = getCanvas(),
context;

canvas.height = diff.height;
canvas.width = diff.width;

div.style.overflow = 'hidden';
a.style.float = 'left';
b.style.float = 'left';
c.style.float = 'left';

context = canvas.getContext('2d');
context.putImageData(diff, 0, 0);

a.appendChild(toCanvas(this.actual));
b.appendChild(toCanvas(expected));
c.appendChild(canvas);

div.appendChild(a);
div.appendChild(b);
div.appendChild(c);

return [
div,
"Expected not to be equal."
];
};
}

return imagediff.equal(this.actual, expected, tolerance);
toImageDiffEqual : function () {
return {
compare: function (actual, expected, tolerance) {
return {
pass: imagediff.equal(actual, expected, tolerance),
message: function () {
var
div = get('div'),
a = get('div', '<div>Actual:</div>'),
b = get('div', '<div>Expected:</div>'),
c = get('div', '<div>Diff:</div>'),
diff = imagediff.diff(actual, expected),
canvas = getCanvas(),
context;

canvas.height = diff.height;
canvas.width = diff.width;

div.style.overflow = 'hidden';
a.style.float = 'left';
b.style.float = 'left';
c.style.float = 'left';

context = canvas.getContext('2d');
context.putImageData(diff, 0, 0);

a.appendChild(toCanvas(actual));
b.appendChild(toCanvas(expected));
c.appendChild(canvas);

div.appendChild(a);
div.appendChild(b);
div.appendChild(c);

return div;
}
};
}
};
}
};

Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
"contributors": [
"Jordan Santell <@jsantell>"
],
"optionalDependencies": {
"canvas": "~1.2.7"
},
"devDependencies": {
"canvas-prebuilt": "^1.6.0",
"jasmine-node": ">=1.0.20",
"smoosh": ">=0.3.1"
},
Expand Down