summaryrefslogtreecommitdiff
path: root/mocha_test
diff options
context:
space:
mode:
authorAlex Early <alexander.early@gmail.com>2016-03-09 13:11:57 -0800
committerAlex Early <alexander.early@gmail.com>2016-03-09 13:11:57 -0800
commit51202cad563a3a386c091eedd6184132756c1117 (patch)
tree5b3504ac0ae6cdfc000114889dff5489ab15eea9 /mocha_test
parentb5ea2b1cd0d01a45aa155663808f0cdf46ff1fe9 (diff)
parent7688e9846e6a87e4107b21ffb57a4492438c64f9 (diff)
downloadasync-51202cad563a3a386c091eedd6184132756c1117.tar.gz
Merge pull request #1049 from caolan/auto-no-deferral
Refactor auto to not need a deferral
Diffstat (limited to 'mocha_test')
-rw-r--r--mocha_test/auto.js41
1 files changed, 25 insertions, 16 deletions
diff --git a/mocha_test/auto.js b/mocha_test/auto.js
index 6b96be4..1850a0c 100644
--- a/mocha_test/auto.js
+++ b/mocha_test/auto.js
@@ -40,7 +40,7 @@ describe('auto', function () {
},
function(err){
expect(err).to.equal(null);
- expect(callOrder).to.eql(['task2','task6','task3','task5','task1','task4']);
+ expect(callOrder).to.eql(['task2','task3','task6','task5','task1','task4']);
done();
});
});
@@ -214,19 +214,8 @@ describe('auto', function () {
// Issue 410 on github: https://github.com/caolan/async/issues/410
it('auto calls callback multiple times', function(done) {
- if (process.browser) {
- // node only test
- return done();
- }
var finalCallCount = 0;
- var domain = require('domain').create();
- domain.on('error', function (e) {
- // ignore test error
- if (!e._test_error) {
- return done(e);
- }
- });
- domain.run(function () {
+ try {
async.auto({
task1: function(callback) { callback(null); },
task2: ['task1', function(results, callback) { callback(null); }]
@@ -239,7 +228,11 @@ describe('auto', function () {
e._test_error = true;
throw e;
});
- });
+ } catch (e) {
+ if (!e._test_error) {
+ throw e;
+ }
+ }
setTimeout(function () {
expect(finalCallCount).to.equal(1);
done();
@@ -293,7 +286,7 @@ describe('auto', function () {
callback(null, 'task1');
}]
});
- }).to.throw;
+ }).to.throw();
done();
});
@@ -308,7 +301,7 @@ describe('auto', function () {
callback(null, 'task2');
}]
});
- }).to.throw;
+ }).to.throw();
done();
});
@@ -356,4 +349,20 @@ describe('auto', function () {
}).to.throw();
});
+ it("should avoid unncecessary deferrals", function (done) {
+ var isSync = true;
+
+ async.auto({
+ step1: function (cb) { cb(null, 1); },
+ step2: ["step1", function (results, cb) {
+ cb();
+ }]
+ }, function () {
+ expect(isSync).to.equal(true);
+ done();
+ });
+
+ isSync = false;
+ });
+
});