Repository navigation
Expand file tree
/
Copy pathsettleParallel.js
More file actions
108 lines (97 loc) · 2.46 KB
/
Copy pathsettleParallel.js
File metadata and controls
108 lines (97 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"use strict";
var expect = require("expect");
var bach = require("../");
function fn1(done) {
done(null, 1);
}
function fn2(done) {
setTimeout(function () {
done(null, 2);
}, 500);
}
function fn3(done) {
done(null, 3);
}
function fnError(done) {
done(new Error("An Error Occurred"));
}
describe("settleParallel", function () {
it("should execute functions in parallel, passing settled results", function (done) {
bach.settleParallel(
fn1,
fn2,
fn3,
)(function (errors, results) {
expect(errors).toEqual(null);
expect(results).toEqual([1, 2, 3]);
done();
});
});
it("allows an array of functions", function (done) {
bach.settleParallel([fn1, fn2, fn3])(function (errors, results) {
expect(errors).toEqual(null);
expect(results).toEqual([1, 2, 3]);
done();
});
});
it("should execute functions in parallel, passing settled errors and results", function (done) {
function slowFn(done) {
setTimeout(function () {
done(null, 2);
}, 500);
}
bach.settleParallel(
fn1,
slowFn,
fn3,
fnError,
)(function (errors, results) {
expect(errors).toBeInstanceOf(Array);
expect(errors[0]).toBeInstanceOf(Error);
expect(results).toEqual([1, 2, 3]);
done();
});
});
it("should take extension points and call them for each function", function (done) {
var arr = [];
var fns = [fn1, fn2, fn3];
bach.settleParallel(fn1, fn2, fn3, {
create: function (fn, idx) {
expect(fns).toContain(fn);
arr[idx] = fn;
return arr;
},
before: function (storage) {
expect(storage).toEqual(arr);
},
after: function (result, storage) {
expect(storage).toEqual(arr);
},
})(function (error) {
expect(error).toEqual(null);
expect(arr).toEqual(fns);
done();
});
});
it("allows array of functions & extensions object", function (done) {
var arr = [];
var fns = [fn1, fn2, fn3];
bach.settleParallel([fn1, fn2, fn3], {
create: function (fn, idx) {
expect(fns).toContain(fn);
arr[idx] = fn;
return arr;
},
before: function (storage) {
expect(storage).toEqual(arr);
},
after: function (result, storage) {
expect(storage).toEqual(arr);
},
})(function (error) {
expect(error).toEqual(null);
expect(arr).toEqual(fns);
done();
});
});
});