From b07c36eab7b3fe5f889d8e55b20dda9585d9d975 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Fri, 20 Jun 2014 12:05:42 -0700 Subject: [PATCH] Use async for flow control --- test/basic-querying.test.js | 16 ++++++---------- test/memory.test.js | 15 +++++---------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/test/basic-querying.test.js b/test/basic-querying.test.js index 12ac4dcf..28fa210b 100644 --- a/test/basic-querying.test.js +++ b/test/basic-querying.test.js @@ -1,5 +1,6 @@ // This test written in mocha+should.js var should = require('./init.js'); +var async = require('async'); var db, User; describe('basic-querying', function () { @@ -578,7 +579,6 @@ describe('basic-querying', function () { }); function seed(done) { - var count = 0; var beatles = [ { seq: 0, @@ -603,15 +603,11 @@ function seed(done) { {seq: 4, name: 'Pete Best', order: 4}, {seq: 5, name: 'Stuart Sutcliffe', order: 3, vip: true} ]; - User.destroyAll(function () { - beatles.forEach(function (beatle) { - User.create(beatle, ok); - }); - }); - function ok() { - if (++count === beatles.length) { - done(); + async.series([ + User.destroyAll.bind(User), + function(cb) { + async.each(beatles, User.create.bind(User), cb); } - } + ], done); } diff --git a/test/memory.test.js b/test/memory.test.js index b98462a1..4016209e 100644 --- a/test/memory.test.js +++ b/test/memory.test.js @@ -142,7 +142,6 @@ describe('Memory connector', function () { }); function seed(done) { - var count = 0; var beatles = [ { seq: 0, @@ -167,17 +166,13 @@ describe('Memory connector', function () { {seq: 4, name: 'Pete Best', order: 4}, {seq: 5, name: 'Stuart Sutcliffe', order: 3, vip: true} ]; - User.destroyAll(function () { - beatles.forEach(function (beatle) { - User.create(beatle, ok); - }); - }); - function ok() { - if (++count === beatles.length) { - done(); + async.series([ + User.destroyAll.bind(User), + function(cb) { + async.each(beatles, User.create.bind(User), cb); } - } + ], done); } });