HumbleSoftware / js-imagediff

JavaScript / Canvas based image diff utility with Jasmine matchers for testing canvas.

Home Page:http://humblesoftware.github.com/js-imagediff/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

branch v1.1: toImageDiffEqual fails headlessly using jasmine 2.1.3 and phantom

hayesmaker opened this issue · comments

I'm using the v1.1 branch for jasmine 2 support,

my toImageDiffEqual test passes in the browser with jasmine, but not headlessly with jasmine and phantom

Is this because v1.1 is not released yet? and if so, does headless testing plan to be supported with jasmine 2+?

The error is quite vague: see below:

screen shot 2015-02-23 at 17 16 40

Test code:

this.compareImage = function (path, done, expect, pixelTolerance) {
        var stage = this.stage;
        stage.update();
        var img = new Image();
        img.src = path;
        img.onload = function () {
            var pixels = this.width * this.height;
            var tolerance = pixels * (typeof pixelTolerance === 'undefined' ? 0.005 : pixelTolerance);
            expect(stage.canvas).toImageDiffEqual(this, tolerance); //###### < ERROR THROWN #######
            done();
        };
        img.onerror = function () {
            fail(img.src + ' failed to load');
            done();
        };
    };

I just fixed imagediff's own jasmine tests to run under PhantomJS (see the karma branch). I did need to set the tolerance to 1 (instead of 0) to make the tests pass there, while all the other browsers are happy with 0 tolerance. So this might work for you as well.

+1 👍 All good with tolerance 1... Nice one. Keep up the good work.

Actually even raising my tolerance from 0.01 to 0.02 fixed the issue, and keeps the accuracy of the tests within acceptable limits.