Skip to content
This repository has been archived by the owner on Dec 6, 2019. It is now read-only.

Allow mismatch tolerance to be specified in grunt task #17

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 0 additions & 3 deletions .bowerrc

This file was deleted.

32 changes: 0 additions & 32 deletions bower.json

This file was deleted.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@
"node": ">= 0.8.0"
},
"scripts": {
"test": "grunt test",
"postinstall": "node ./node_modules/bower/bin/bower install"
"test": "grunt test"
},
"devDependencies": {
"grunt-contrib-jshint": "~0.6.0",
"grunt-contrib-clean": "~0.4.0",
"grunt-contrib-nodeunit": "~0.2.0",
"grunt": "~0.4.1"
"grunt": "~0.4.1",
"phantomjs": "~1.9.2-2"
},
"dependencies": {
"bower": "~1.0.3",
"phantomcss": "0.3.0",
"temporary": "0.0.7"
},
"peerDependencies": {
Expand Down
1 change: 1 addition & 0 deletions phantomjs/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ phantomcss.init({
screenshotRoot: args.screenshots,
failedComparisonsRoot: args.failures,
libraryRoot: phantomCSSPath, // Give absolute path, otherwise PhantomCSS fails
mismatchTolerance: args.mismatchTolerance,

onFail: function(test) {
sendMessage('onFail', test);
Expand Down
55 changes: 36 additions & 19 deletions tasks/phantomcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var path = require('path');
var tmp = require('temporary');
var phantomBinaryPath = require('phantomjs').path;
var runnerPath = path.join(__dirname, '..', 'phantomjs', 'runner.js');
var phantomCSSPath = path.join(__dirname, '..', 'bower_components', 'phantomcss');
var phantomCSSPath = path.join(__dirname, '..', 'node_modules', 'phantomcss');

module.exports = function(grunt) {
grunt.registerMultiTask('phantomcss', 'CSS Regression Testing', function() {
Expand All @@ -21,7 +21,8 @@ module.exports = function(grunt) {
screenshots: 'screenshots',
results: 'results',
viewportSize: [1280, 800],
logLevel: 'error'
logLevel: 'error',
mismatchTolerance: 1.00
});

// Timeout ID for message checking loop
Expand Down Expand Up @@ -164,21 +165,37 @@ module.exports = function(grunt) {
// Start watching for messages
checkForMessages();

grunt.util.spawn({
cmd: phantomBinaryPath,
args: [
runnerPath,
JSON.stringify(options)
],
opts: {
cwd: cwd,
stdio: 'inherit'
}
}, function(error, result, code) {
// When Phantom exits check for remaining messages one last time
checkForMessages(true);
//FailSafe PhantomJS
var complete = this.async();
var count = 0;
var retry = function () {
grunt.util.spawn({
cmd: phantomBinaryPath,
args: [
runnerPath,
JSON.stringify(options)
],
opts: {
cwd: cwd,
stdio: 'inherit'
}
}, function (error, result, code) {
count++;
if (error && code === 1 /*error code thrown by when phantomjs fails*/) {
if(count < 8) {
grunt.log.writeln("Retrying phantomcss tests up to 7 times. Try: " + count);
retry();
} else {
checkForMessages(true);
cleanup(error);
complete(false);
}
} else {
complete(result);
}
});
};
retry();
});
};

cleanup(error);
});
});
};