UNPKG

3.74 kBJavaScriptView Raw
1var TaskList = require('../lib/taskList');
2var Session = require('../lib/session');
3var assert = require('assert');
4
5suite('TaskList', function() {
6 test('register and run', function(done) {
7 var optionsList = [];
8 var session = new Session('host');
9 TaskList.registerTask('simpleTask', function(_session, options, callback) {
10 assert.equal(session, _session);
11 optionsList.push(options);
12 callback();
13 });
14
15 var taskList = new TaskList('simple', {pretty: false});
16 taskList.simpleTask('Simple Name', {aa: 10});
17 taskList.simpleTask('Simple Name2', {aa: 20});
18 taskList.run(session, function(summeryMap) {
19 assert.deepEqual(summeryMap[session._host], {error: null, history: [
20 {task: 'Simple Name', status: 'SUCCESS'},
21 {task: 'Simple Name2', status: 'SUCCESS'}
22 ]});
23 assert.deepEqual(optionsList, [{aa: 10}, {aa: 20}]);
24 done();
25 });
26 });
27
28 test('when error', function(done) {
29 var session = new Session('host');
30 TaskList.registerTask('simpleTask2', function(_session, options, callback) {
31 assert.equal(session, _session);
32 if(options.aa == 20) {
33 callback(new Error('error-here'));
34 } else {
35 callback();
36 }
37 });
38
39 var taskList = new TaskList('simple', {pretty: false});
40 taskList.simpleTask2('one', {aa: 10});
41 taskList.simpleTask2('two', {aa: 20});
42 taskList.simpleTask2('three', {aa: 30});
43 taskList.run(session, function(summeryMap) {
44 var summery = summeryMap[session._host];
45 assert.equal(summery.error.message, 'error-here');
46 assert.deepEqual(summery.history, [
47 {task: 'one', status: 'SUCCESS'},
48 {task: 'two', status: 'FAILED', error: 'error-here'}
49 ]);
50 done();
51 });
52 });
53
54 test('when error - with ignoreErrors', function(done) {
55 var session = new Session('host');
56 TaskList.registerTask('simpleTask3', function(_session, options, callback) {
57 assert.equal(session, _session);
58 if(options.aa == 20) {
59 callback(new Error('error-here'));
60 } else {
61 callback();
62 }
63 });
64
65 var taskList = new TaskList('simple', {pretty: false, ignoreErrors: true});
66 taskList.simpleTask3('one', {aa: 10});
67 taskList.simpleTask3('two', {aa: 20});
68 taskList.simpleTask3('three', {aa: 30});
69 taskList.run(session, function(summeryMap) {
70 var summery = summeryMap[session._host];
71 assert.ifError(summery.error);
72 assert.deepEqual(summery.history, [
73 {task: 'one', status: 'SUCCESS'},
74 {task: 'two', status: 'FAILED', error: 'error-here'},
75 {task: 'three', status: 'SUCCESS'},
76 ]);
77 done();
78 });
79 });
80
81 test('concat', function(done) {
82 var optionsList = [];
83 var session = new Session('host');
84 TaskList.registerTask('simpleTask', function(_session, options, callback) {
85 assert.equal(session, _session);
86 optionsList.push(options);
87 callback();
88 });
89
90 var tl1 = new TaskList('one', {pretty: false});
91 tl1.simpleTask('Simple Name', {aa: 10});
92 tl1.simpleTask('Simple Name2', {aa: 20});
93
94 var tl2 = new TaskList('two', {pretty: false});
95 tl2.simpleTask('Simple Name', {aa: 30});
96 tl2.simpleTask('Simple Name2', {aa: 40});
97
98 var tl3 = new TaskList('three', {pretty: false});
99 tl3.simpleTask('Simple Name', {aa: 50});
100 tl3.simpleTask('Simple Name2', {aa: 60});
101
102 var combined = tl1.concat([tl2, tl3]);
103 assert.equal(combined._name, tl1._name + '+');
104
105 combined.run(session, function(summeryMap) {
106 assert.ifError(summeryMap[session._host].error);
107 assert.deepEqual(optionsList, [
108 {aa: 10}, {aa: 20}, {aa: 30}, {aa: 40}, {aa: 50}, {aa: 60}
109 ]);
110 done();
111 });
112 });
113});
\No newline at end of file