dialect-module-configuration.test.js
1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict';
const chai = require('chai'),
expect = chai.expect,
path = require('path'),
Support = require(`${__dirname}/support`),
Sequelize = Support.Sequelize,
dialect = Support.getTestDialect();
describe(Support.getTestDialectTeaser('Sequelize'), () => {
describe('dialectModule options', () => {
it('options.dialectModule', () => {
const dialectModule = {
verbose: () => { return dialectModule; }
};
const sequelize = new Sequelize('dbname', 'root', 'pass', {
port: 999,
dialect,
dialectModule
});
expect(sequelize.connectionManager.lib).to.equal(dialectModule);
});
it('options.dialectModulePath', () => {
let dialectPath = path.join(process.cwd(), 'node_modules');
switch (dialect) {
case 'postgres': dialectPath = path.join(dialectPath, 'pg'); break;
case 'mysql': dialectPath = path.join(dialectPath, 'mysql2'); break;
case 'mssql': dialectPath = path.join(dialectPath, 'tedious'); break;
case 'sqlite': dialectPath = path.join(dialectPath, 'sqlite3'); break;
default: throw Error('Unsupported dialect');
}
// this will throw if invalid path is passed
new Sequelize('dbname', 'root', 'pass', {
port: 999,
dialect,
dialectModulePath: dialectPath
});
});
it('options.dialectModulePath fails for invalid path', () => {
expect(() => {
new Sequelize('dbname', 'root', 'pass', {
port: 999,
dialect,
dialectModulePath: '/foo/bar/baz'
});
}).to.throw('Unable to find dialect at /foo/bar/baz');
});
});
});