Skip to content

Instantly share code, notes, and snippets.

@jcjc
Created September 19, 2011 04:19
Show Gist options
  • Save jcjc/1225954 to your computer and use it in GitHub Desktop.
Save jcjc/1225954 to your computer and use it in GitHub Desktop.
Layout testing
var runTests = function(callback) {
var testsFinishedCount = 0;
var testFailures = [];
var layouts = config.SETTINGS.layouts;
var processNextLayout = function() {
var layout = layouts.shift();
if (layout) {
var rasterizeCmd = RASTERIZE_CMD_TEMPLATE({
url: buildUrl(layout.url),
path: config.SETTINGS.tmpPath + layout.page + '.png'
});
exec(rasterizeCmd, function(output) {
var diffCmd = DIFF_CMD_TEMPLATE({
file1: config.SETTINGS.baselinePath + layout.page + '.png',
file2: config.SETTINGS.tmpPath + layout.page + '.png',
});
exec(diffCmd, function(error, stdout, stderr) {
var result = parseDiff(stdout);
var failed = result && result.diffAmount > config.SETTINGS.tolerancePercent;
if (failed) {
testFailures.push({
page: layout.page,
diffAmount: result.diffAmount
});
}
testsFinishedCount++;
processNextLayout();
});
});
} else {
callback(testsFinishedCount, testFailures);
}
};
processNextLayout();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment