<commit_before>var describer;
if (window.indexedDB) {
    describer = describe;
} else {
    describer = describe.skip;
    console.log('IndexedDB is not supported on this platform'); // eslint-disable-line no-console
}

function connectToDb(callback) {
    var db;
    var req = indexedDB.open(KvKeeper.dbName, KvKeeper.dbVersion);

    req.onsuccess = function (event) {
        db = event.target.result;

        db.onversionchange = function () {
            throw new Error('Version changed');
        };

        callback(db);
    };

    req.onupgradeneeded = function (event) {
        db = event.target.result;

        KvKeeper.StorageDB.setupSchema(db);
    };

    req.onblocked = req.onerror = function (event) {
        throw new Error('Connect error: ' + event.type);
    };
}

testDbOnPositive('clear table', function (callback) {
    connectToDb(function (db) {
        var store = db.transaction([KvKeeper.storeName], 'readwrite').objectStore(KvKeeper.storeName);

        store.clear();
        db.close();

        callback();
    });
});

// Skipping tests with drop database by default
// because of troubles with closing databases on deletion
// in some old browsers and Safari
testDbOnPositive('drop database', function (callback) {
    var req = indexedDB.deleteDatabase(KvKeeper.dbName);

    req.onsuccess = function () {
        callback();
    };

    req.onblocked = req.onerror = function (event) {
        throw new Error('Drop DB error! ' + event.type);
    };
}, true);

function testDbOnPositive(label, resetDb, skip) {
    var localDescriber = skip ? describe.skip : describer;

    localDescriber('KvKeeper.StorageDB on positive with ' + label, function () {
        var secondDb;

        beforeEach(function (done) {
            resetDb(function () {
                connectToDb(function (db) {
                    secondDb = db;
                    done();
                });
            });
        });

        afterEach(function (done) {
            KvKeeper.getStorage('db', function (err, storage) {
                assert.notOk(err);

                storage.close();
                secondDb.close();
<commit_msg>Add param for skipping drop DB tests<commit_after>var describer;
if (window.indexedDB) {
    describer = describe;
} else {
    describer = describe.skip;
    console.log('IndexedDB is not supported on this platform'); // eslint-disable-line no-console
}

function connectToDb(callback) {
    var db;
    var req = indexedDB.open(KvKeeper.dbName, KvKeeper.dbVersion);

    req.onsuccess = function (event) {
        db = event.target.result;

        db.onversionchange = function () {
            throw new Error('Version changed');
        };

        callback(db);
    };

    req.onupgradeneeded = function (event) {
        db = event.target.result;

        KvKeeper.StorageDB.setupSchema(db);
    };

    req.onblocked = req.onerror = function (event) {
        throw new Error('Connect error: ' + event.type);
    };
}

testDbOnPositive('clear table', function (callback) {
    connectToDb(function (db) {
        var store = db.transaction([KvKeeper.storeName], 'readwrite').objectStore(KvKeeper.storeName);

        store.clear();
        db.close();

        callback();
    });
});

// Skipping tests with drop database by default
// because of troubles with closing databases on deletion
// in some old browsers and Safari
testDbOnPositive('drop database', function (callback) {
    var req = indexedDB.deleteDatabase(KvKeeper.dbName);

    req.onsuccess = function () {
        callback();
    };

    req.onblocked = req.onerror = function (event) {
        throw new Error('Drop DB error! ' + event.type);
    };
}, location.href.indexOf('tests=all') == -1);

function testDbOnPositive(label, resetDb, skip) {
    var localDescriber = skip ? describe.skip : describer;

    localDescriber('KvKeeper.StorageDB on positive with ' + label, function () {
        var secondDb;

        beforeEach(function (done) {
            resetDb(function () {
                connectToDb(function (db) {
                    secondDb = db;
                    done();
                });
            });
        });

        afterEach(function (done) {
            KvKeeper.getStorage('db', function (err, storage) {
                assert.notOk(err);

                storage.close();
                secondDb.close();

{'fraction_non_alphanumeric': 0.12234649623373658, 'fraction_numerical': 0.00022825838849577722, 'mean_word_length': 2.299698795180723, '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': '945071', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1236, 'n_words': 291}