Added support for building typescript outside of Visual Studio (npm run build), added webpack support for building a web-compatible unit tests package, added a test.html file for running unit tests inside a browser, added support for using actual websql and indexeddb in the unit tests, fixed bugs in the unit tests where it wasn't closing dbproviders between unit tests, causing indexeddb to crap out between runs on a real browser.
This commit is contained in:
Родитель
551b21c611
Коммит
2cc5377c0a
|
@ -1,17 +1,21 @@
|
|||
"use strict";
|
||||
var assert = require('assert');
|
||||
var _ = require('lodash');
|
||||
var SyncTasks = require('synctasks');
|
||||
var sqlite3 = require('sqlite3');
|
||||
var indexeddbjs = require('indexeddb-js');
|
||||
var NoSqlProvider = require('../NoSqlProvider');
|
||||
var NoSqlProviderUtils = require('../NoSqlProviderUtils');
|
||||
// Don't trap exceptions so we immediately see them with a stack trace
|
||||
SyncTasks.config.catchExceptions = false;
|
||||
function openProvider(providerName, schema) {
|
||||
var provider = null;
|
||||
if (providerName === 'sqlite3test') {
|
||||
var sqlite3 = require('sqlite3');
|
||||
provider = new NoSqlProvider.NodeSqlite3MemoryDbProvider(sqlite3);
|
||||
}
|
||||
else if (providerName === 'indexeddbtest') {
|
||||
var sqlite3 = require('sqlite3');
|
||||
var engine = new sqlite3.Database(':memory:');
|
||||
var indexeddbjs = require('indexeddb-js');
|
||||
var scope = indexeddbjs.makeScope('sqlite3', engine);
|
||||
global['IDBKeyRange'] = scope.IDBKeyRange;
|
||||
var idbFactory = scope.indexedDB;
|
||||
|
@ -20,10 +24,16 @@ function openProvider(providerName, schema) {
|
|||
else if (providerName === 'memory') {
|
||||
provider = new NoSqlProvider.InMemoryProvider();
|
||||
}
|
||||
else if (providerName === 'indexeddb') {
|
||||
provider = new NoSqlProvider.IndexedDbProvider();
|
||||
}
|
||||
else if (providerName === 'websql') {
|
||||
provider = new NoSqlProvider.WebSqlProvider();
|
||||
}
|
||||
return NoSqlProvider.openListOfProviders([provider], 'test', schema, true);
|
||||
}
|
||||
describe('NoSqlProvider', function () {
|
||||
var provsToTest = ['sqlite3test', 'indexeddbtest', 'memory'];
|
||||
var provsToTest = typeof window === 'undefined' ? ['sqlite3test', 'indexeddbtest', 'memory'] : ['indexeddb' /*, 'websql'*/];
|
||||
it('Number/value/type sorting', function () {
|
||||
var pairsToTest = [
|
||||
[0, 1],
|
||||
|
@ -157,7 +167,12 @@ describe('NoSqlProvider', function () {
|
|||
assert.equal(ret.length, 1, 'getRange2-+');
|
||||
[3].forEach(function (v) { assert(_.find(ret, function (r) { return r.val === 'val' + v; })); });
|
||||
});
|
||||
return SyncTasks.whenAll([tt1, tt2, tt3]);
|
||||
return SyncTasks.whenAll([tt1, tt2, tt3]).then(function () {
|
||||
return prov.close();
|
||||
});
|
||||
}
|
||||
else {
|
||||
return prov.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -178,6 +193,7 @@ describe('NoSqlProvider', function () {
|
|||
return prov.getAll('test').then(function (ret2) {
|
||||
assert.equal(ret2.length, 1);
|
||||
assert.equal(ret2[0].val, 'b');
|
||||
return prov.close();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -322,7 +338,9 @@ describe('NoSqlProvider', function () {
|
|||
assert.equal(ret.length, 2);
|
||||
ret.forEach(function (r) { assert.equal(r.val, 'b'); });
|
||||
});
|
||||
return SyncTasks.whenAll([g1, g2, g2b, g2c, g3, g4]);
|
||||
return SyncTasks.whenAll([g1, g2, g2b, g2c, g3, g4]).then(function () {
|
||||
return prov.close();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,20 +2,21 @@
|
|||
import _ = require('lodash');
|
||||
import SyncTasks = require('synctasks');
|
||||
|
||||
import sqlite3 = require('sqlite3');
|
||||
import indexeddbjs = require('indexeddb-js');
|
||||
|
||||
import NoSqlProvider = require('../NoSqlProvider');
|
||||
import NoSqlProviderUtils = require('../NoSqlProviderUtils');
|
||||
import IndexedDbProvider = require('../IndexedDbProvider');
|
||||
import InMemoryProvider = require('../InMemoryProvider');
|
||||
|
||||
// Don't trap exceptions so we immediately see them with a stack trace
|
||||
SyncTasks.config.catchExceptions = false;
|
||||
|
||||
function openProvider(providerName: string, schema: NoSqlProvider.DbSchema) {
|
||||
let provider: NoSqlProvider.DbProvider = null;
|
||||
if (providerName === 'sqlite3test') {
|
||||
var sqlite3 = require('sqlite3');
|
||||
provider = new NoSqlProvider.NodeSqlite3MemoryDbProvider(sqlite3);
|
||||
} else if (providerName === 'indexeddbtest') {
|
||||
var sqlite3 = require('sqlite3');
|
||||
const engine = new sqlite3.Database(':memory:');
|
||||
var indexeddbjs = require('indexeddb-js');
|
||||
const scope = indexeddbjs.makeScope('sqlite3', engine);
|
||||
global['IDBKeyRange'] = scope.IDBKeyRange;
|
||||
|
||||
|
@ -23,12 +24,16 @@ function openProvider(providerName: string, schema: NoSqlProvider.DbSchema) {
|
|||
provider = new NoSqlProvider.IndexedDbProvider(idbFactory, false);
|
||||
} else if (providerName === 'memory') {
|
||||
provider = new NoSqlProvider.InMemoryProvider();
|
||||
} else if (providerName === 'indexeddb') {
|
||||
provider = new NoSqlProvider.IndexedDbProvider();
|
||||
} else if (providerName === 'websql') {
|
||||
provider = new NoSqlProvider.WebSqlProvider();
|
||||
}
|
||||
return NoSqlProvider.openListOfProviders([provider], 'test', schema, true);
|
||||
}
|
||||
|
||||
describe('NoSqlProvider', function () {
|
||||
let provsToTest = ['sqlite3test', 'indexeddbtest', 'memory'];
|
||||
let provsToTest = typeof window === 'undefined' ? ['sqlite3test', 'indexeddbtest', 'memory'] : ['indexeddb', 'websql'];
|
||||
|
||||
it('Number/value/type sorting', () => {
|
||||
const pairsToTest = [
|
||||
|
@ -184,7 +189,11 @@ describe('NoSqlProvider', function () {
|
|||
[3].forEach(v => { assert(_.find(ret, r => r.val === 'val' + v)); });
|
||||
});
|
||||
|
||||
return SyncTasks.whenAll([tt1, tt2, tt3]);
|
||||
return SyncTasks.whenAll([tt1, tt2, tt3]).then(() => {
|
||||
return prov.close();
|
||||
});
|
||||
} else {
|
||||
return prov.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -207,6 +216,8 @@ describe('NoSqlProvider', function () {
|
|||
return prov.getAll<any>('test').then(ret2 => {
|
||||
assert.equal(ret2.length, 1);
|
||||
assert.equal(ret2[0].val, 'b');
|
||||
|
||||
return prov.close();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -358,7 +369,9 @@ describe('NoSqlProvider', function () {
|
|||
assert.equal(ret.length, 2);
|
||||
ret.forEach(r => { assert.equal(r.val, 'b'); });
|
||||
});
|
||||
return SyncTasks.whenAll([g1, g2, g2b, g2c, g3, g4]);
|
||||
return SyncTasks.whenAll([g1, g2, g2b, g2c, g3, g4]).then(() => {
|
||||
return prov.close();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Mocha Tests</title>
|
||||
<link href="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.css" rel="stylesheet" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="mocha"></div>
|
||||
|
||||
<script src="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.js"></script>
|
||||
|
||||
<script>mocha.setup('bdd')</script>
|
||||
<script src="NoSqlProviderTestsPack.js"></script>
|
||||
<script>
|
||||
mocha.checkLeaks();
|
||||
mocha.run();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"declaration": false,
|
||||
"noResolve": false,
|
||||
"module": "commonjs",
|
||||
"target": "es5"
|
||||
},
|
||||
|
||||
"filesGlob": [
|
||||
"src/**/*{ts,tsx}",
|
||||
"src/typings/**/*.d.ts"
|
||||
],
|
||||
|
||||
"compilerOptions": {
|
||||
"outDir": "dist/"
|
||||
},
|
||||
|
||||
"exclude": [
|
||||
"dist",
|
||||
"node_modules"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
var path = require('path');
|
||||
var webpack = require('webpack');
|
||||
|
||||
var webpackConfig = {
|
||||
entry: './src/tests/NoSqlProviderTests.ts',
|
||||
|
||||
output: {
|
||||
filename: './NoSQLProviderTestsPack.js',
|
||||
},
|
||||
|
||||
resolve: {
|
||||
root: [
|
||||
path.resolve('./src'),
|
||||
path.resolve('./node_modules')
|
||||
],
|
||||
extensions: ['', '.ts', '.js']
|
||||
},
|
||||
|
||||
externals: [ 'sqlite3', 'indexeddb-js' ],
|
||||
|
||||
module: {
|
||||
loaders: [{
|
||||
// Compile TS.
|
||||
test: /\.tsx?$/,
|
||||
exclude: /node_modules/,
|
||||
loader: 'ts-loader'
|
||||
}]
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = webpackConfig;
|
Загрузка…
Ссылка в новой задаче