knex/test/tape/knex.js

81 lines
1.7 KiB
JavaScript
Raw Normal View History

2015-05-01 14:55:53 -04:00
'use strict';
const knex = require('../../src/index');
const test = require('tape');
test('it should parse the connection string', function(t) {
t.plan(1);
const knexObj = knex({
client: 'mysql',
connection: 'mysql://user:password@localhost/dbname',
});
t.deepEqual(knexObj.client.config.connection, {
database: 'dbname',
2016-09-13 18:12:23 -04:00
host: 'localhost',
password: 'password',
user: 'user',
});
knexObj.destroy();
});
test('it should allow to use proprietary dialect', function(t) {
t.plan(2);
const Client = require('../../src/dialects/mysql');
const knexObj = knex({
client: Client,
2016-05-19 13:32:07 +03:00
connection: {
database: 'dbname',
2016-09-13 18:12:23 -04:00
host: 'localhost',
2016-05-19 13:32:07 +03:00
password: 'password',
user: 'user',
},
});
t.ok(knexObj.client instanceof Client);
2016-05-19 13:32:07 +03:00
t.deepEqual(knexObj.client.config, {
client: Client,
2016-05-19 13:32:07 +03:00
connection: {
database: 'dbname',
2016-09-13 18:12:23 -04:00
host: 'localhost',
2016-05-19 13:32:07 +03:00
password: 'password',
user: 'user',
},
});
knexObj.destroy();
});
2016-10-09 14:00:55 -04:00
test('it should use knex supported dialect', function(t) {
t.plan(1);
const knexObj = knex({
client: 'postgres',
2016-05-19 13:32:07 +03:00
connection: {
database: 'dbname',
2016-09-13 18:12:23 -04:00
host: 'localhost',
2016-05-19 13:32:07 +03:00
password: 'password',
user: 'user',
},
});
2016-05-19 13:32:07 +03:00
t.deepEqual(knexObj.client.config, {
client: 'postgres',
2016-05-19 13:32:07 +03:00
connection: {
database: 'dbname',
2016-09-13 18:12:23 -04:00
host: 'localhost',
2016-05-19 13:32:07 +03:00
password: 'password',
user: 'user',
},
});
knexObj.destroy();
});
test('it should throw error if client is omitted in config', function(t) {
t.plan(1);
try {
knex({});
t.deepEqual(true, false); //Don't reach this point
} catch (error) {
t.deepEqual(
error.message,
"knex: Required configuration option 'client' is missing."
);
}
});