-
-
Notifications
You must be signed in to change notification settings - Fork 128
/
concurrent.js
86 lines (76 loc) · 1.45 KB
/
concurrent.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
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
import {serial as test} from 'ava';
import delay from 'delay';
import Listr from '..';
import SimpleRenderer from './fixtures/simple-renderer';
import {testOutput} from './fixtures/utils';
const tasks = [
{
title: 'P1',
task: () => delay(100)
},
{
title: 'P2',
task: () => delay(200)
},
{
title: 'P3',
task: () => delay(300)
},
{
title: 'P4',
task: () => delay(400)
}
];
test('run tasks sequentially if concurrency is undefined', async t => {
const list = new Listr(tasks, {
renderer: SimpleRenderer
});
testOutput(t, [
'P1 [started]',
'P1 [completed]',
'P2 [started]',
'P2 [completed]',
'P3 [started]',
'P3 [completed]',
'P4 [started]',
'P4 [completed]',
'done'
]);
await list.run();
});
test('run tasks in parallel if concurrency is true', async t => {
const list = new Listr(tasks, {
renderer: SimpleRenderer,
concurrent: true
});
testOutput(t, [
'P1 [started]',
'P2 [started]',
'P3 [started]',
'P4 [started]',
'P1 [completed]',
'P2 [completed]',
'P3 [completed]',
'P4 [completed]',
'done'
]);
await list.run();
});
test('run tasks in sequential parallel chunks, if concurrency is a number', async t => {
const list = new Listr(tasks, {
renderer: SimpleRenderer,
concurrent: 2
});
testOutput(t, [
'P1 [started]',
'P2 [started]',
'P1 [completed]',
'P3 [started]',
'P2 [completed]',
'P4 [started]',
'P3 [completed]',
'P4 [completed]',
'done'
]);
await list.run();
});