Skip to content

Commit

Permalink
Update indexing event test to use async/await instead of callbacks
Browse files Browse the repository at this point in the history
Co-Authored-By: James Coglan <9265+jcoglan@users.noreply.github.com>
  • Loading branch information
AlbaHerrerias and jcoglan committed Jul 27, 2021
1 parent 733eded commit f30b9fb
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions tests/integration/test.design_docs.js
Expand Up @@ -96,37 +96,34 @@ adapters.forEach(function (adapter) {
});
});

it('Indexing event', function (done) {
var docs1 = [
it('Indexing event', async () => {
const docs1 = [
doc,
{_id: 'dale', score: 3},
{_id: 'mikeal', score: 5},
{_id: 'max', score: 4},
{_id: 'nuno', score: 3},
];
var db = new PouchDB(dbs.name);
let db = new PouchDB(dbs.name);
// Test invalid if adapter doesnt support mapreduce
if (!db.query || adapter !== 'local') {
return done();
return;
}

let indexingEvents = [];

db.on('indexing', function (result) {
db.on('indexing', (result) => {
indexingEvents.push(result);
});

db.bulkDocs({ docs: docs1 }, function () {
db.query('foo/scores', { reduce: false }, function () {
indexingEvents.length.should.equal(2);
indexingEvents[0]['indexed_docs'].should.equal(0);
indexingEvents[1]['last_seq'].should.equal(5);
indexingEvents[1]['results_count'].should.equal(5);
indexingEvents[1]['indexed_docs'].should.equal(5);
await db.bulkDocs({ docs: docs1 });
await db.query('foo/scores', { reduce: false });

done();
});
});
indexingEvents.length.should.equal(2);
indexingEvents[0]['indexed_docs'].should.equal(0);
indexingEvents[1]['last_seq'].should.equal(5);
indexingEvents[1]['results_count'].should.equal(5);
indexingEvents[1]['indexed_docs'].should.equal(5);
});

it('Concurrent queries', function (done) {
Expand Down

0 comments on commit f30b9fb

Please sign in to comment.