Adaptive loading of dblite test based on whether the module exists
This commit is contained in:
parent
5f1ec50e0b
commit
df9dfcdebc
@ -7,22 +7,33 @@ var tests = testBase.tests;
|
|||||||
|
|
||||||
// Load the test config file
|
// Load the test config file
|
||||||
var adapterName = 'dblite';
|
var adapterName = 'dblite';
|
||||||
|
var sqlite = null;
|
||||||
|
var connection = null;
|
||||||
|
|
||||||
// Set up the connection
|
// Set up the connection
|
||||||
var sqlite = require(adapterName).withSQLite('3.8.6+');
|
try {
|
||||||
var connection = sqlite(':memory:');
|
sqlite = require(adapterName).withSQLite('3.8.6+');
|
||||||
|
connection = sqlite(':memory:');
|
||||||
|
} catch (e) {
|
||||||
|
// Export an empty testsuite if module not loaded
|
||||||
|
console.log(e);
|
||||||
|
console.log("Database adapter dblite not found");
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
// Set up the query builder object
|
if (connection)
|
||||||
var nodeQuery = require('../../lib/node-query');
|
{
|
||||||
var qb = nodeQuery('sqlite', connection, adapterName);
|
// Set up the query builder object
|
||||||
|
var nodeQuery = require('../../lib/node-query');
|
||||||
|
var qb = nodeQuery('sqlite', connection, adapterName);
|
||||||
|
|
||||||
// Set up the sqlite database
|
// Set up the sqlite database
|
||||||
var sql = 'CREATE TABLE IF NOT EXISTS "create_test" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);' +
|
var sql = 'CREATE TABLE IF NOT EXISTS "create_test" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);' +
|
||||||
'CREATE TABLE IF NOT EXISTS "create_join" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);';
|
'CREATE TABLE IF NOT EXISTS "create_join" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);';
|
||||||
connection.query(sql);
|
connection.query(sql);
|
||||||
|
|
||||||
// Set up the test base
|
// Set up the test base
|
||||||
testBase._setUp(qb, function(test, err, rows) {
|
testBase._setUp(qb, function(test, err, rows) {
|
||||||
if (err != null) {
|
if (err != null) {
|
||||||
test.done();
|
test.done();
|
||||||
throw new Error(err);
|
throw new Error(err);
|
||||||
@ -35,16 +46,24 @@ testBase._setUp(qb, function(test, err, rows) {
|
|||||||
|
|
||||||
test.ok(rows, 'dblite: Valid result for generated query');
|
test.ok(rows, 'dblite: Valid result for generated query');
|
||||||
test.done();
|
test.done();
|
||||||
});
|
});
|
||||||
|
|
||||||
tests["dblite adapter with query builder"] = function(test) {
|
tests["dblite adapter with query builder"] = function(test) {
|
||||||
test.expect(1);
|
test.expect(1);
|
||||||
test.ok(testBase.qb);
|
test.ok(testBase.qb);
|
||||||
|
|
||||||
// Close the db connection
|
// Close the db connection
|
||||||
connection.close();
|
connection.close();
|
||||||
test.done();
|
test.done();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Export the final test object
|
||||||
|
module.exports = tests;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
module.exports = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Export the final test object
|
|
||||||
module.exports = tests;
|
|
Loading…
Reference in New Issue
Block a user