Skip to content

Commit 5464736

Browse files
Alejandro Henkelphated
Alejandro Henkel
authored andcommittedFeb 26, 2017
Fix: Validate series/parallel arguments aren't empty or invalid (fixes #72) (#75)
1 parent 212fd7d commit 5464736

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed
 

‎lib/helpers/normalizeArgs.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ function normalizeArgs(registry, args) {
1616
return fn;
1717
}
1818

19-
return map(flatten(args), getFunction);
19+
var flattenArgs = flatten(args);
20+
assert(flattenArgs.length, 'One or more tasks should be combined using series or parallel');
21+
22+
return map(flattenArgs, getFunction);
2023
}
2124

2225
module.exports = normalizeArgs;

‎test/parallel.js

+45
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,51 @@ describe('parallel', function() {
3434
done();
3535
});
3636

37+
it('should throw on non-valid tasks combined with valid tasks', function(done) {
38+
function fail() {
39+
taker.parallel('test1', 'test2', 'test3', {});
40+
}
41+
42+
expect(fail).toThrow(/Task never defined:/);
43+
done();
44+
});
45+
46+
it('should throw on tasks array with both valid and non-valid tasks', function(done) {
47+
function fail() {
48+
taker.parallel(['test1', 'test2', 'test3', {}]);
49+
}
50+
51+
expect(fail).toThrow(/Task never defined:/);
52+
done();
53+
});
54+
55+
it('should throw on non-valid task', function(done) {
56+
function fail() {
57+
taker.parallel({});
58+
}
59+
60+
expect(fail).toThrow(/Task never defined:/);
61+
done();
62+
});
63+
64+
it('should throw when no tasks specified', function(done) {
65+
function fail() {
66+
taker.parallel();
67+
}
68+
69+
expect(fail).toThrow(/One or more tasks should be combined using series or parallel/);
70+
done();
71+
});
72+
73+
it('should throw on empty array of registered tasks', function(done) {
74+
function fail() {
75+
taker.parallel([]);
76+
}
77+
78+
expect(fail).toThrow(/One or more tasks should be combined using series or parallel/);
79+
done();
80+
});
81+
3782
it('should take only one array of registered tasks', function(done) {
3883
taker.parallel(['test1', 'test2', 'test3'])(function(err, results) {
3984
expect(results).toEqual([1, 2, 3]);

‎test/series.js

+45
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,51 @@ describe('series', function() {
3434
done();
3535
});
3636

37+
it('should throw on non-valid tasks combined with valid tasks', function(done) {
38+
function fail() {
39+
taker.series('test1', 'test2', 'test3', {});
40+
}
41+
42+
expect(fail).toThrow(/Task never defined:/);
43+
done();
44+
});
45+
46+
it('should throw on tasks array with both valid and non-valid tasks', function(done) {
47+
function fail() {
48+
taker.series(['test1', 'test2', 'test3', {}]);
49+
}
50+
51+
expect(fail).toThrow(/Task never defined:/);
52+
done();
53+
});
54+
55+
it('should throw on non-valid task', function(done) {
56+
function fail() {
57+
taker.series({});
58+
}
59+
60+
expect(fail).toThrow(/Task never defined:/);
61+
done();
62+
});
63+
64+
it('should throw when no tasks specified', function(done) {
65+
function fail() {
66+
taker.series();
67+
}
68+
69+
expect(fail).toThrow(/One or more tasks should be combined using series or parallel/);
70+
done();
71+
});
72+
73+
it('should throw on empty array of registered tasks', function(done) {
74+
function fail() {
75+
taker.series([]);
76+
}
77+
78+
expect(fail).toThrow(/One or more tasks should be combined using series or parallel/);
79+
done();
80+
});
81+
3782
it('should take only one array of registered tasks', function(done) {
3883
taker.series(['test1', 'test2', 'test3'])(function(err, results) {
3984
expect(results).toEqual([1, 2, 3]);

0 commit comments

Comments
 (0)
Please sign in to comment.