<commit_before>let t = require('../test-lib/test.js');
let assert = require('assert');

let apos;

describe('Db', function() {

  this.timeout(t.timeout);

  it('should exist on the apos object', function(done) {
    apos = require('../index.js')({
      root: module,
      shortName: 'test',

      afterInit: function(callback) {
        assert(apos.db);
        // Verify a normal, boring connection to localhost without the db option worked
        return apos.docs.db.findOne().then(function(doc) {
          assert(doc);
          return done();
        }).catch(function(err) {
          console.error(err);
          assert(false);
        });
      }
    });
  });

  it('should be able to launch a second instance reusing the connection', function(done) {
    let apos2 = require('../index.js')({
      root: module,
      shortName: 'test2',
      modules: {
        'apostrophe-express': {
          port: 7777
        },
        'apostrophe-db': {
          db: apos.db,
          uri: 'mongodb://this-will-not-work-unless-db-successfully-overrides-it/fail'
        }
      },
      afterInit: function(callback) {
        return apos.docs.db.findOne().then(function(doc) {
          assert(doc);
          return t.destroy(apos2, function() {
            return t.destroy(apos, done);
          });
        }).catch(function(err) {
          console.error(err);
          assert(false);
        });
      }
    });
  });
});<commit_msg>Converts db test to async-await<commit_after>const t = require('../test-lib/test.js');
const assert = require('assert');
let apos;

describe('Db', function() {
  after(async function () {
    return t.destroy(apos);
  });

  this.timeout(t.timeout);

  it('should exist on the apos object', async function() {
    apos = await require('../index.js')({
      root: module,
      shortName: 'test',
      argv: {
        _: []
      }
    });

    assert(apos.db);
    // Verify a normal, boring connection to localhost without the db option worked
    const doc = await apos.docs.db.findOne();

    assert(doc);
  });

  it('should be able to launch a second instance reusing the connection', async function() {
    const apos2 = await require('../index.js')({
      root: module,
      shortName: 'test2',
      argv: {
        _: []
      },
      modules: {
        'apostrophe-express': {
          port: 7777
        },
        'apostrophe-db': {
          db: apos.db,
          uri: 'mongodb://this-will-not-work-unless-db-successfully-overrides-it/fail'
        }
      }
    });

    const doc = await apos.docs.db.findOne();

    assert(doc);

    return t.destroy(apos2);
  });
});
{'fraction_non_alphanumeric': 0.1570779712339137, 'fraction_numerical': 0.005299015897047691, 'mean_word_length': 2.0732558139534882, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2034254', 'n_tokens_mistral': 837, 'n_tokens_neox': 819, 'n_words': 180}