-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
61 lines (55 loc) · 1.58 KB
/
test.js
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
'use strict'
let PrecisePromiseAll = require('./index.js');
var should = require('should');
let promiseTasks = [];
before(() => {
let timoutPromise = (ms) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (ms > 400) {
return reject(new Error('timeout'));
} else {
resolve();
}
}, ms);
});
};
// Add tasks
promiseTasks.push(timoutPromise.bind(null, 100));
promiseTasks.push(timoutPromise.bind(null, 200));
promiseTasks.push(timoutPromise.bind(null, 300));
promiseTasks.push(timoutPromise.bind(null, 400));
promiseTasks.push(timoutPromise.bind(null, 500)); // will be rejected
});
describe('PrecisePromiseAll', () => {
it('in sequential', (done) => {
PrecisePromiseAll.sequential(promiseTasks)
.then((result) => {
Object.keys(result.resolved).length.should.eql(4);
Object.keys(result.rejected).length.should.eql(1);
Object.keys(result.rejected).forEach((index) => {
result.rejected[index].should.be.Function;
});
done();
})
.catch(function(err) {
console.log(err.toString());
done();
});
});
it('in parallel', (done) => {
PrecisePromiseAll.parallel(promiseTasks)
.then((result) => {
Object.keys(result.resolved).length.should.eql(4);
Object.keys(result.rejected).length.should.eql(1);
Object.keys(result.rejected).forEach((index) => {
result.rejected[index].should.be.Function;
});
done();
})
.catch(function(err) {
console.log(err.toString());
done();
});
});
});