From cadf4ef434e517e47c4e9ca1db5b89e892ff5981 Mon Sep 17 00:00:00 2001 From: Louis Chatriot Date: Sun, 14 Feb 2016 18:53:44 -0800 Subject: [PATCH] Updated browser tests --- browser-version/out/nedb.js | 3 ++- browser-version/test/nedb-browser.js | 23 +++++++++++++---------- lib/datastore.js | 3 ++- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/browser-version/out/nedb.js b/browser-version/out/nedb.js index ef6854d..e9655bf 100755 --- a/browser-version/out/nedb.js +++ b/browser-version/out/nedb.js @@ -1315,7 +1315,7 @@ Datastore.prototype.updateIndexes = function (oldDoc, newDoc) { * * @param {Query} query * @param {Boolean} dontExpireStaleDocs Optional, defaults to false, if true don't remove stale docs. Useful for the remove function which shouldn't be impacted by expirations - * @param {Function} callback Signature err, docs + * @param {Function} callback Signature err, candidates */ Datastore.prototype.getCandidates = function (query, dontExpireStaleDocs, callback) { var indexNames = Object.keys(this.indexes) @@ -1327,6 +1327,7 @@ Datastore.prototype.getCandidates = function (query, dontExpireStaleDocs, callba dontExpireStaleDocs = false; } + async.waterfall([ // STEP 1: get candidates list by checking indexes from most to least frequent usecase function (cb) { diff --git a/browser-version/test/nedb-browser.js b/browser-version/test/nedb-browser.js index e7e903a..f451f42 100755 --- a/browser-version/test/nedb-browser.js +++ b/browser-version/test/nedb-browser.js @@ -254,19 +254,22 @@ describe('Indexing', function () { db.insert({ a: 4 }, function () { db.insert({ a: 6 }, function () { db.insert({ a: 7 }, function () { - var candidates = db.getCandidates({ a: 6 }) - assert.equal(candidates.length, 3); - assert.isDefined(_.find(candidates, function (doc) { return doc.a === 4; })); - assert.isDefined(_.find(candidates, function (doc) { return doc.a === 6; })); - assert.isDefined(_.find(candidates, function (doc) { return doc.a === 7; })); + db.getCandidates({ a: 6 }, function (err, candidates) { + console.log(candidates); + assert.equal(candidates.length, 3); + assert.isDefined(_.find(candidates, function (doc) { return doc.a === 4; })); + assert.isDefined(_.find(candidates, function (doc) { return doc.a === 6; })); + assert.isDefined(_.find(candidates, function (doc) { return doc.a === 7; })); - db.ensureIndex({ fieldName: 'a' }); + db.ensureIndex({ fieldName: 'a' }); - candidates = db.getCandidates({ a: 6 }) - assert.equal(candidates.length, 1); - assert.isDefined(_.find(candidates, function (doc) { return doc.a === 6; })); + db.getCandidates({ a: 6 }, function (err, candidates) { + assert.equal(candidates.length, 1); + assert.isDefined(_.find(candidates, function (doc) { return doc.a === 6; })); - done(); + done(); + }); + }); }); }); }); diff --git a/lib/datastore.js b/lib/datastore.js index e179dcd..4b978ad 100755 --- a/lib/datastore.js +++ b/lib/datastore.js @@ -250,7 +250,7 @@ Datastore.prototype.updateIndexes = function (oldDoc, newDoc) { * * @param {Query} query * @param {Boolean} dontExpireStaleDocs Optional, defaults to false, if true don't remove stale docs. Useful for the remove function which shouldn't be impacted by expirations - * @param {Function} callback Signature err, docs + * @param {Function} callback Signature err, candidates */ Datastore.prototype.getCandidates = function (query, dontExpireStaleDocs, callback) { var indexNames = Object.keys(this.indexes) @@ -262,6 +262,7 @@ Datastore.prototype.getCandidates = function (query, dontExpireStaleDocs, callba dontExpireStaleDocs = false; } + async.waterfall([ // STEP 1: get candidates list by checking indexes from most to least frequent usecase function (cb) {