<commit_before>
describe('LowlaDB API', function() {
  it('exists', function() {
    should.exist(LowlaDB);
  });

  describe('Collections', function() {
    var indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.oIndexedDB || window.msIndexedDB;
    beforeEach(function(done) {
      var req = indexedDB.deleteDatabase( "lowla" );
      req.onsuccess = function () {
        done();
      };

      req.onerror = function () {
        done('failed to delete db in beforeEach');
      };

      req.onblocked = function () {
        console.log( 'db blocked' );
      };
    });

    var coll = LowlaDB.collection('dbName', 'collectionOne');
    var collTwo = LowlaDB.collection('dbName', 'collectionTwo');

    afterEach(function() {
      LowlaDB.close();
    });

    it('can be created', function() {
      should.exist(coll);
      coll.insert.should.be.a('function');<commit_msg>Tests for LowlaDB on()/emit()/off() event API.<commit_after>
describe('LowlaDB API', function() {

  describe('Events', function() {
    afterEach(function() {
      LowlaDB.off();
    });

    it('can register and receive a single event', function() {
      var cb = sinon.stub();
      LowlaDB.on('myEvent', cb);
      LowlaDB.emit('myEvent');
      cb.callCount.should.equal(1);
      LowlaDB.emit('myEvent');
      cb.callCount.should.equal(2);
    });

    it('can register multiple listeners to one event', function() {
      var cb1 = sinon.stub();
      var cb2 = sinon.stub();
      LowlaDB.on('myEvent', cb1);
      LowlaDB.on('myEvent', cb2);
      LowlaDB.emit('myEvent');
      cb1.callCount.should.equal(1);
      cb2.callCount.should.equal(1);
      LowlaDB.emit('myEvent');
      cb1.callCount.should.equal(2);
      cb2.callCount.should.equal(2);
    });

    it('can register multiple events', function() {
      var cb1 = sinon.stub();
      var cb2 = sinon.stub();
      LowlaDB.on('myEvent', cb1);
      LowlaDB.on('myEvent2', cb2);
      LowlaDB.emit('myEvent');
      cb1.callCount.should.equal(1);
      cb2.callCount.should.equal(0);
      LowlaDB.emit('myEvent2');
      cb1.callCount.should.equal(1);
      cb2.callCount.should.equal(1);
    });

    it('can remove a listener from an event', function() {
      var cb1 = sinon.stub();
      var cb2 = sinon.stub();
      LowlaDB.on('myEvent', cb1);
      LowlaDB.on('myEvent', cb2);
      LowlaDB.emit('myEvent');
      cb1.callCount.should.equal(1);
      cb2.callCount.should.equal(1);
      LowlaDB.off('myEvent', cb1);
      LowlaDB.emit('myEvent');
      cb1.callCount.should.equal(1);
      cb2.callCount.should.equal(2);
    });

    it('can remove all listeners from an event', function() {
      var cb1 = sinon.stub();
      var cb2 = sinon.stub();
      var cb3 = sinon.stub();
      LowlaDB.on('myEvent', cb1);
      LowlaDB.on('myEvent', cb2);
      LowlaDB.on('myEvent3', cb3);
      LowlaDB.emit('myEvent');
      cb1.callCount.should.equal(1);
      cb2.callCount.should.equal(1);
      cb3.callCount.should.equal(0);
      LowlaDB.emit('myEvent3');
      cb3.callCount.should.equal(1);
      LowlaDB.off('myEvent');
      LowlaDB.emit('myEvent');
      cb1.callCount.should.equal(1);
      cb2.callCount.should.equal(1);
      cb3.callCount.should.equal(1);
      LowlaDB.emit('myEvent3');
      cb3.callCount.should.equal(2);
    });
  });

  describe('Collections', function() {
    var indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.oIndexedDB || window.msIndexedDB;
    beforeEach(function(done) {
      var req = indexedDB.deleteDatabase( "lowla" );
      req.onsuccess = function () {
        done();
      };

      req.onerror = function () {
        done('failed to delete db in beforeEach');
      };

      req.onblocked = function () {
        console.log( 'db blocked' );
      };
    });

    var coll = LowlaDB.collection('dbName', 'collectionOne');
    var collTwo = LowlaDB.collection('dbName', 'collectionTwo');

    afterEach(function() {
      LowlaDB.close();
    });

    it('can be created', function() {
      should.exist(coll);
      coll.insert.should.be.a('function');
{'fraction_non_alphanumeric': 0.16730861819932596, 'fraction_numerical': 0.015888300433317286, 'mean_word_length': 2.7231182795698925, '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': '2187506', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1388, 'n_words': 235}