Skip to content

Commit

Permalink
Fix: Validate series/parallel arguments aren't empty or invalid (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro Henkel authored and phated committed Feb 26, 2017
1 parent 212fd7d commit 5464736
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/helpers/normalizeArgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ function normalizeArgs(registry, args) {
return fn;
}

return map(flatten(args), getFunction);
var flattenArgs = flatten(args);
assert(flattenArgs.length, 'One or more tasks should be combined using series or parallel');

return map(flattenArgs, getFunction);
}

module.exports = normalizeArgs;
45 changes: 45 additions & 0 deletions test/parallel.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,51 @@ describe('parallel', function() {
done();
});

it('should throw on non-valid tasks combined with valid tasks', function(done) {
function fail() {
taker.parallel('test1', 'test2', 'test3', {});
}

expect(fail).toThrow(/Task never defined:/);
done();
});

it('should throw on tasks array with both valid and non-valid tasks', function(done) {
function fail() {
taker.parallel(['test1', 'test2', 'test3', {}]);
}

expect(fail).toThrow(/Task never defined:/);
done();
});

it('should throw on non-valid task', function(done) {
function fail() {
taker.parallel({});
}

expect(fail).toThrow(/Task never defined:/);
done();
});

it('should throw when no tasks specified', function(done) {
function fail() {
taker.parallel();
}

expect(fail).toThrow(/One or more tasks should be combined using series or parallel/);
done();
});

it('should throw on empty array of registered tasks', function(done) {
function fail() {
taker.parallel([]);
}

expect(fail).toThrow(/One or more tasks should be combined using series or parallel/);
done();
});

it('should take only one array of registered tasks', function(done) {
taker.parallel(['test1', 'test2', 'test3'])(function(err, results) {
expect(results).toEqual([1, 2, 3]);
Expand Down
45 changes: 45 additions & 0 deletions test/series.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,51 @@ describe('series', function() {
done();
});

it('should throw on non-valid tasks combined with valid tasks', function(done) {
function fail() {
taker.series('test1', 'test2', 'test3', {});
}

expect(fail).toThrow(/Task never defined:/);
done();
});

it('should throw on tasks array with both valid and non-valid tasks', function(done) {
function fail() {
taker.series(['test1', 'test2', 'test3', {}]);
}

expect(fail).toThrow(/Task never defined:/);
done();
});

it('should throw on non-valid task', function(done) {
function fail() {
taker.series({});
}

expect(fail).toThrow(/Task never defined:/);
done();
});

it('should throw when no tasks specified', function(done) {
function fail() {
taker.series();
}

expect(fail).toThrow(/One or more tasks should be combined using series or parallel/);
done();
});

it('should throw on empty array of registered tasks', function(done) {
function fail() {
taker.series([]);
}

expect(fail).toThrow(/One or more tasks should be combined using series or parallel/);
done();
});

it('should take only one array of registered tasks', function(done) {
taker.series(['test1', 'test2', 'test3'])(function(err, results) {
expect(results).toEqual([1, 2, 3]);
Expand Down

0 comments on commit 5464736

Please sign in to comment.