From da680ec2a88102dc87b1280f31e10b7b20cf8fa6 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Mon, 22 Feb 2016 16:07:55 +0100 Subject: [PATCH] Code re-org --- test/support/assert.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/test/support/assert.js b/test/support/assert.js index f3e9cc20..7cb363d1 100644 --- a/test/support/assert.js +++ b/test/support/assert.js @@ -39,6 +39,22 @@ assert.imageBuffersAreSimilar = function(bufferA, bufferB, tolerance, callback) imagesAreSimilar(testImage, referenceImage, tolerance, callback); }; +assert.imageIsSimilarToFile = function(testImage, referenceImageRelativeFilePath, tolerance, callback) { + callback = callback || function(err) { assert.ifError(err); }; + + var referenceImageFilePath = path.resolve(referenceImageRelativeFilePath); + + var referenceImage = mapnik.Image.fromBytes(fs.readFileSync(referenceImageFilePath, { encoding: null })); + + imagesAreSimilar(testImage, referenceImage, tolerance, function(err) { + if (err) { + var testImageFilePath = randomImagePath(); + testImage.save(testImageFilePath); + } + callback(err); + }); +}; + function imagesAreSimilar(testImage, referenceImage, tolerance, callback) { if (testImage.width() !== referenceImage.width() || testImage.height() !== referenceImage.height()) { return callback(new Error('Images are not the same size')); @@ -59,22 +75,6 @@ function imagesAreSimilar(testImage, referenceImage, tolerance, callback) { } } -assert.imageIsSimilarToFile = function(testImage, referenceImageRelativeFilePath, tolerance, callback) { - callback = callback || function(err) { assert.ifError(err); }; - - var referenceImageFilePath = path.resolve(referenceImageRelativeFilePath); - - var referenceImage = mapnik.Image.fromBytes(fs.readFileSync(referenceImageFilePath, { encoding: null })); - - imagesAreSimilar(testImage, referenceImage, tolerance, function(err) { - if (err) { - var testImageFilePath = randomImagePath(); - testImage.save(testImageFilePath); - } - callback(err); - }); -}; - function randomImagePath() { return path.resolve('test/results/png/image-test-' + Date.now() + '.png'); }