Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect the force #57

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
73 changes: 50 additions & 23 deletions tasks/casper.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ 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) == 'array') error = (error.length > 0);
if (error) {
return done(false);
}
Expand All @@ -32,38 +33,64 @@ 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('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) {
callback(err);
});
}, concurrency);

queue.drain = function() {
taskComplete(queue_errors);
};
}
}

grunt.util.async.forEachSeries(this.files, function(file, iteratorCb) {

if (file.src.length) {
//Allow Files in each task to be run concurrently
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('ignore-fail')) {
file.src.forEach(function(srcFile) {
queue.push({file: srcFile, dest: file.dest}, function (err) {
if (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.writeln('error:', err);
//Call Done and Log Duration
iteratorCb(err);
});
}

}
} else {

Expand Down
10 changes: 6 additions & 4 deletions tasks/lib/casper.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ exports.init = function (grunt) {
grunt.verbose.write('Found CasperJS Executable', casperBin);

//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) {

Expand All @@ -113,10 +113,12 @@ 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');
if (result.stdout) grunt.log.write('\n' + result.stdout + '\n\n');
if (result.stderr) grunt.log.write('\n' + result.stderr + '\n\n');

next();
});

}
};

Expand Down