Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

compat.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * tests/compat.js: Some of the APIs provided by vasync are intended to be
  3. * API-compatible with node-async, so we incorporate the tests from node-async
  4. * directly here. These are copied from https://github.com/caolan/async,
  5. * available under the MIT license. To make it easy to update this from the
  6. * source, this file should remain unchanged from the source except for this
  7. * header comment, the change to the "require" line, and deleted lines for
  8. * unimplemented functions.
  9. *
  10. * The following tests are deliberately omitted:
  11. *
  12. * o "waterfall non-array": Per Joyent's Best Practices for Node.js Error
  13. * Handling, we're strict about argument types and throw on these programmer
  14. * errors rather than emitting them asynchronously.
  15. *
  16. * o "waterfall multiple callback calls": We deliberately disallow a waterfall
  17. * function to invoke its callback more than once, so we don't test for that
  18. * here. The behavior that node-async allows can potentially be used to fork
  19. * the waterfall, which may be useful, but it's often used instead as an
  20. * excuse to write code sloppily. And the downside is that it makes it really
  21. * hard to understand bugs where the waterfall was resumed too early. For
  22. * now, we're disallowing it, but if the forking behavior becomes useful, we
  23. * can always make our version less strict.
  24. */
  25. var async = require('../lib/vasync');
  26. exports['waterfall'] = function(test){
  27. test.expect(6);
  28. var call_order = [];
  29. async.waterfall([
  30. function(callback){
  31. call_order.push('fn1');
  32. setTimeout(function(){callback(null, 'one', 'two');}, 0);
  33. },
  34. function(arg1, arg2, callback){
  35. call_order.push('fn2');
  36. test.equals(arg1, 'one');
  37. test.equals(arg2, 'two');
  38. setTimeout(function(){callback(null, arg1, arg2, 'three');}, 25);
  39. },
  40. function(arg1, arg2, arg3, callback){
  41. call_order.push('fn3');
  42. test.equals(arg1, 'one');
  43. test.equals(arg2, 'two');
  44. test.equals(arg3, 'three');
  45. callback(null, 'four');
  46. },
  47. function(arg4, callback){
  48. call_order.push('fn4');
  49. test.same(call_order, ['fn1','fn2','fn3','fn4']);
  50. callback(null, 'test');
  51. }
  52. ], function(err){
  53. test.done();
  54. });
  55. };
  56. exports['waterfall empty array'] = function(test){
  57. async.waterfall([], function(err){
  58. test.done();
  59. });
  60. };
  61. exports['waterfall no callback'] = function(test){
  62. async.waterfall([
  63. function(callback){callback();},
  64. function(callback){callback(); test.done();}
  65. ]);
  66. };
  67. exports['waterfall async'] = function(test){
  68. var call_order = [];
  69. async.waterfall([
  70. function(callback){
  71. call_order.push(1);
  72. callback();
  73. call_order.push(2);
  74. },
  75. function(callback){
  76. call_order.push(3);
  77. callback();
  78. },
  79. function(){
  80. test.same(call_order, [1,2,3]);
  81. test.done();
  82. }
  83. ]);
  84. };
  85. exports['waterfall error'] = function(test){
  86. test.expect(1);
  87. async.waterfall([
  88. function(callback){
  89. callback('error');
  90. },
  91. function(callback){
  92. test.ok(false, 'next function should not be called');
  93. callback();
  94. }
  95. ], function(err){
  96. test.equals(err, 'error');
  97. });
  98. setTimeout(test.done, 50);
  99. };