diff options
Diffstat (limited to 'tests/lib/screenshot-testing/support')
-rw-r--r-- | tests/lib/screenshot-testing/support/chai-extras.js | 24 | ||||
-rw-r--r-- | tests/lib/screenshot-testing/support/globals.js | 2 | ||||
-rw-r--r-- | tests/lib/screenshot-testing/support/test-environment.js | 8 |
3 files changed, 28 insertions, 6 deletions
diff --git a/tests/lib/screenshot-testing/support/chai-extras.js b/tests/lib/screenshot-testing/support/chai-extras.js index 1253f8fb13..f2c7f0544d 100644 --- a/tests/lib/screenshot-testing/support/chai-extras.js +++ b/tests/lib/screenshot-testing/support/chai-extras.js @@ -108,6 +108,14 @@ function capture(screenName, compareAgainst, selector, pageSetupFn, done) { done(error); }; + var pass = function () { + if (options['print-logs']) { + console.log(getPageLogsString(pageRenderer.pageLogs, " ")); + } + + done(); + }; + if (!testInfo.processed) { fail("Failed to generate screenshot to " + screenshotFileName + "."); return; @@ -121,16 +129,20 @@ function capture(screenName, compareAgainst, selector, pageSetupFn, done) { var expected = fs.read(expectedScreenshotPath), processed = fs.read(processedScreenshotPath); - if (expected != processed) { - fail("Processed screenshot does not match expected for " + screenshotFileName + "."); + if (processed == expected) { + pass(); return; } - if (options['print-logs']) { - console.log(getPageLogsString(pageRenderer.pageLogs, " ")); - } + // if the files are not exact, perform a diff to check if they are truly different + resemble("file://" + processedScreenshotPath).compareTo("file://" + expectedScreenshotPath).onComplete(function(data) { + if (data.misMatchPercentage != 0) { + fail("Processed screenshot does not match expected for " + screenshotFileName + "."); + return; + } - done(); + pass(); + }); }, selector); } catch (ex) { var err = new Error(ex.message); diff --git a/tests/lib/screenshot-testing/support/globals.js b/tests/lib/screenshot-testing/support/globals.js index 1cd9b782fd..53d8d050e5 100644 --- a/tests/lib/screenshot-testing/support/globals.js +++ b/tests/lib/screenshot-testing/support/globals.js @@ -21,6 +21,8 @@ var mochaPath = path.join(testsLibDir, config.mocha, "mocha.js"); var chaiPath = path.join(testsLibDir, config.chai, "chai.js"); +var resemblePath = path.join(testsLibDir, 'resemblejs', 'resemble.js'); + var expect = function () { return chai.expect.apply(chai.expect, arguments); }; diff --git a/tests/lib/screenshot-testing/support/test-environment.js b/tests/lib/screenshot-testing/support/test-environment.js index e7a0f1f44e..375408e562 100644 --- a/tests/lib/screenshot-testing/support/test-environment.js +++ b/tests/lib/screenshot-testing/support/test-environment.js @@ -118,6 +118,13 @@ TestingEnvironment.prototype.executeConsoleCommand = function (command, args, ca child.on("exit", callback); }; +TestingEnvironment.prototype.addPluginOnCmdLineToTestEnv = function () { + if (options.plugin) { + this.pluginsToLoad = [options.plugin]; + this.save(); + } +}; + var droppedOnce = false; TestingEnvironment.prototype.setupFixture = function (fixtureClass, done) { console.log(" Setting up fixture " + fixtureClass + "..."); @@ -140,6 +147,7 @@ TestingEnvironment.prototype.setupFixture = function (fixtureClass, done) { var self = this; this.executeConsoleCommand('tests:setup-fixture', args, function (code) { self.reload(); + self.addPluginOnCmdLineToTestEnv(); console.log(); |