UNPKG

2.5 kBJavaScriptView Raw
1var async = require('../lib/vasync');
2
3/*
4 * tryEach tests, transliterated from mocha to tap.
5 *
6 * They are nearly identical except for some details related to vasync. For
7 * example, we don't support calling the callback more than once from any of
8 * the given functions.
9 */
10
11
12exports['tryEach no callback'] = function (test) {
13 async.tryEach([]);
14 test.done();
15};
16exports['tryEach empty'] = function (test) {
17 async.tryEach([], function (err, results) {
18 test.equals(err, null);
19 test.same(results, undefined);
20 test.done();
21 });
22};
23exports['tryEach one task, multiple results'] = function (test) {
24 var RESULTS = ['something', 'something2'];
25 async.tryEach([
26 function (callback) {
27 callback(null, RESULTS[0], RESULTS[1]);
28 }
29 ], function (err, results) {
30 test.equals(err, null);
31 test.same(results, RESULTS);
32 test.done();
33 });
34};
35exports['tryEach one task'] = function (test) {
36 var RESULT = 'something';
37 async.tryEach([
38 function (callback) {
39 callback(null, RESULT);
40 }
41 ], function (err, results) {
42 test.equals(err, null);
43 test.same(results, RESULT);
44 test.done();
45 });
46};
47exports['tryEach two tasks, one failing'] = function (test) {
48 var RESULT = 'something';
49 async.tryEach([
50 function (callback) {
51 callback(new Error('Failure'), {});
52 },
53 function (callback) {
54 callback(null, RESULT);
55 }
56 ], function (err, results) {
57 test.equals(err, null);
58 test.same(results, RESULT);
59 test.done();
60 });
61};
62exports['tryEach two tasks, both failing'] = function (test) {
63 var ERROR_RESULT = new Error('Failure2');
64 async.tryEach([
65 function (callback) {
66 callback(new Error('Should not stop here'));
67 },
68 function (callback) {
69 callback(ERROR_RESULT);
70 }
71 ], function (err, results) {
72 test.equals(err, ERROR_RESULT);
73 test.same(results, undefined);
74 test.done();
75 });
76};
77exports['tryEach two tasks, non failing'] = function (test) {
78 var RESULT = 'something';
79 async.tryEach([
80 function (callback) {
81 callback(null, RESULT);
82 },
83 function () {
84 test.fail('Should not been called');
85 }
86 ], function (err, results) {
87 test.equals(err, null);
88 test.same(results, RESULT);
89 test.done();
90 });
91};