From 4d56f39313e6b2cec403d9299767f17f250c2fac Mon Sep 17 00:00:00 2001 From: James Kiefer Date: Wed, 17 Sep 2014 17:05:27 +0000 Subject: [PATCH 1/8] use grunt.util.async.queue if --force is set --- tasks/casper.js | 72 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 23 deletions(-) diff --git a/tasks/casper.js b/tasks/casper.js index 635afae..043d8c8 100644 --- a/tasks/casper.js +++ b/tasks/casper.js @@ -32,6 +32,37 @@ module.exports = function (grunt) { grunt.verbose.writeflags(args, 'Arguments'); + if (options.parallel) { + //https://github.com/gruntjs/grunt-contrib-sass/issues/16 + //Set Default Concurrency at 5 (Supposed Memory Leak > 10) + var concurrency = 5; + if (options.concurrency) { + if (options.concurrency > 10 ) { + grunt.verbose.writeln('Concurrency Too High. Max 10, updating to 10.'); + concurrency = 10; + } else if (options.concurrency < 1) { + grunt.verbose.writeln('Concurrency Too Low. Min 1, updating to default 5.'); + } else { + concurrency = options.concurrency; + } + //Don't Pass this through to spawn + delete options.concurrency; + } + + if (grunt.option('force')) { + var queue_errors = []; + var queue = grunt.util.async.queue(function (task, callback) { + casperLib.execute(task.file, task.dest !== 'src' ? task.dest : null, options, args, function(err) { + callback(err); + }); + }, concurrency); + + queue.drain = function() { + taskComplete(queue_errors); + }; + } + } + grunt.util.async.forEachSeries(this.files, function(file, iteratorCb) { if (file.src.length) { @@ -39,31 +70,26 @@ module.exports = function (grunt) { if (options.parallel) { //Don't Pass this through to spawn delete options.parallel; - //https://github.com/gruntjs/grunt-contrib-sass/issues/16 - //Set Default Concurrency at 5 (Supposed Memory Leak > 10) - var concurrency = 5; - if (options.concurrency) { - if (options.concurrency > 10 ) { - grunt.verbose.writeln('Concurrency Too High. Max 10, updating to 10.'); - concurrency = 10; - } else if (options.concurrency < 1) { - grunt.verbose.writeln('Concurrency Too Low. Min 1, updating to default 5.'); - } else { - concurrency = options.concurrency; - } - //Don't Pass this through to spawn - delete options.concurrency; - } + //Run Tests In Parallel if (file.src) { - grunt.util.async.forEachLimit(file.src, concurrency, function(srcFile, next) { - //Spawn Child Process - casperLib.execute(srcFile, file.dest !== 'src' ? file.dest : null, options, args, next); - }, function(err) { - if (err) grunt.log.write('error:', err); - //Call Done and Log Duration - iteratorCb(err); - }); + if (grunt.option('force')) { + file.src.forEach(function(srcFile) { + queue.push({file: srcFile, dest: file.dest}, function (err) { + queue_errors.push(err); + }); + }); + } else { + grunt.util.async.forEachLimit(file.src, concurrency, function(srcFile, next) { + //Spawn Child Process + casperLib.execute(srcFile, file.dest !== 'src' ? file.dest : null, options, args, next); + }, function(err) { + if (err) grunt.log.write('error:', err); + //Call Done and Log Duration + iteratorCb(err); + }); + } + } } else { From 5eee2104698ba0bbef604e5055aad5807fa90294 Mon Sep 17 00:00:00 2001 From: James Kiefer Date: Wed, 17 Sep 2014 18:27:11 +0000 Subject: [PATCH 2/8] flag is now --ignore-fail because --force causes the exit status to be 0 small bugfixes --- tasks/casper.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tasks/casper.js b/tasks/casper.js index 043d8c8..4e5dce8 100644 --- a/tasks/casper.js +++ b/tasks/casper.js @@ -24,7 +24,7 @@ module.exports = function (grunt) { var msg = "Casper Task '" + taskName + "' took ~" + new Duration(startTime).milliseconds + "ms to run"; grunt.log.success(msg); - if (error) { + if (grunt.util.kindOf(error) != 'null') { return done(false); } done(); @@ -49,7 +49,7 @@ module.exports = function (grunt) { delete options.concurrency; } - if (grunt.option('force')) { + if (grunt.option('ignore-fail')) { var queue_errors = []; var queue = grunt.util.async.queue(function (task, callback) { casperLib.execute(task.file, task.dest !== 'src' ? task.dest : null, options, args, function(err) { @@ -73,7 +73,7 @@ module.exports = function (grunt) { //Run Tests In Parallel if (file.src) { - if (grunt.option('force')) { + if (grunt.option('ignore-fail')) { file.src.forEach(function(srcFile) { queue.push({file: srcFile, dest: file.dest}, function (err) { queue_errors.push(err); @@ -84,7 +84,7 @@ module.exports = function (grunt) { //Spawn Child Process casperLib.execute(srcFile, file.dest !== 'src' ? file.dest : null, options, args, next); }, function(err) { - if (err) grunt.log.write('error:', err); + if (err) grunt.log.writeln('error:', err); //Call Done and Log Duration iteratorCb(err); }); From 7a96d4393a47f2f74c2b15feea294fdbd2b37008 Mon Sep 17 00:00:00 2001 From: James Kiefer Date: Wed, 17 Sep 2014 19:24:25 +0000 Subject: [PATCH 3/8] bugfix --- tasks/casper.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tasks/casper.js b/tasks/casper.js index 4e5dce8..2369549 100644 --- a/tasks/casper.js +++ b/tasks/casper.js @@ -24,7 +24,8 @@ module.exports = function (grunt) { var msg = "Casper Task '" + taskName + "' took ~" + new Duration(startTime).milliseconds + "ms to run"; grunt.log.success(msg); - if (grunt.util.kindOf(error) != 'null') { + if (grunt.util.kindOf(error) == 'array') error = (error.length > 0); + if (error) { return done(false); } done(); @@ -76,7 +77,7 @@ module.exports = function (grunt) { if (grunt.option('ignore-fail')) { file.src.forEach(function(srcFile) { queue.push({file: srcFile, dest: file.dest}, function (err) { - queue_errors.push(err); + if (err) queue_errors.push(err); }); }); } else { From 79583ab25dc62348d8b37471d0affdea32cfd560 Mon Sep 17 00:00:00 2001 From: James Kiefer Date: Tue, 28 Apr 2015 17:02:08 +0000 Subject: [PATCH 4/8] Buffer test output so that parallel tests logs don't mix print a . on every line recieved so we can still get some progressive feedback --- tasks/lib/casper.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tasks/lib/casper.js b/tasks/lib/casper.js index f8a6855..7fcd70d 100644 --- a/tasks/lib/casper.js +++ b/tasks/lib/casper.js @@ -97,14 +97,16 @@ exports.init = function (grunt) { grunt.verbose.write('Found CasperJS Executable', casperBin); + var out = ''; + //Spawn Casper Process - grunt.util.spawn({ + var child = grunt.util.spawn({ cmd : casperBin, args : args, opts : { cwd : cwd, //see CasperJs output live - stdio : 'inherit' + //stdio : 'inherit' } }, function (errorObj, result, code) { @@ -115,8 +117,17 @@ exports.init = function (grunt) { if (result.stdout) grunt.log.write(result.stdout + '\n\n'); if (result.stderr) grunt.log.write(result.stderr + '\n\n'); + + grunt.log.writeln(out); + next(); }); + + child.stdout.on('data', function(buf) { + grunt.log.write('.'); + out += String(buf); + }); + } }; From 15916143e8457241bef08a1efe0b9df4e9ba543d Mon Sep 17 00:00:00 2001 From: James Kiefer Date: Wed, 29 Apr 2015 06:12:51 +0000 Subject: [PATCH 5/8] cleanup --- tasks/lib/casper.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tasks/lib/casper.js b/tasks/lib/casper.js index 7fcd70d..6b748d2 100644 --- a/tasks/lib/casper.js +++ b/tasks/lib/casper.js @@ -97,8 +97,6 @@ exports.init = function (grunt) { grunt.verbose.write('Found CasperJS Executable', casperBin); - var out = ''; - //Spawn Casper Process var child = grunt.util.spawn({ cmd : casperBin, @@ -115,17 +113,14 @@ exports.init = function (grunt) { return next(true); } - if (result.stdout) grunt.log.write(result.stdout + '\n\n'); - if (result.stderr) grunt.log.write(result.stderr + '\n\n'); - - grunt.log.writeln(out); + if (result.stdout) grunt.log.write('\n' + result.stdout + '\n\n'); + if (result.stderr) grunt.log.write('\n' + result.stderr + '\n\n'); next(); }); child.stdout.on('data', function(buf) { grunt.log.write('.'); - out += String(buf); }); } From 7db6688026f438a490c0a0cc4f70276436d8b46d Mon Sep 17 00:00:00 2001 From: James Kiefer Date: Wed, 29 Apr 2015 14:47:05 +0000 Subject: [PATCH 6/8] remove 'progressive output' it was mostly unhelpful --- tasks/lib/casper.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tasks/lib/casper.js b/tasks/lib/casper.js index 6b748d2..fbc83b0 100644 --- a/tasks/lib/casper.js +++ b/tasks/lib/casper.js @@ -119,10 +119,6 @@ exports.init = function (grunt) { next(); }); - child.stdout.on('data', function(buf) { - grunt.log.write('.'); - }); - } }; From 30727abb8883f8ed254f38343d7559aa1b47cac9 Mon Sep 17 00:00:00 2001 From: James Kiefer Date: Tue, 17 May 2016 17:22:21 +0000 Subject: [PATCH 7/8] upgrade phantomjs possible fix for intermittent hang problem --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ae6af0f..d172e79 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "casperjs": "~1.1.0-beta3", "duration": "~0.2.0", "lodash": "~2.4.1", - "phantomjs": "~1.9.7-1", + "phantomjs": "~2.1.1", "slimerjs": "^0.9.1-2" } } From 67592a9e6ddd87be40b054023a397107de8f22f1 Mon Sep 17 00:00:00 2001 From: James Kiefer Date: Wed, 1 Jun 2016 17:22:38 +0000 Subject: [PATCH 8/8] revert 30727ab --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d172e79..ae6af0f 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "casperjs": "~1.1.0-beta3", "duration": "~0.2.0", "lodash": "~2.4.1", - "phantomjs": "~2.1.1", + "phantomjs": "~1.9.7-1", "slimerjs": "^0.9.1-2" } }