Update dependencies, and fix linting issues

This commit is contained in:
Timothy Warren 2018-02-02 11:50:29 -05:00
parent 806a1e1702
commit a94038cd47
39 changed files with 226 additions and 458 deletions

View File

@ -34,5 +34,6 @@
"callback-return": [1],
"object-shorthand": [1, "methods"],
"prefer-template": [1]
}
}
},
"parser": "babel-eslint"
}

View File

@ -1,5 +1,3 @@
'use strict';
/**
* Class that wraps database connection libraries
*

View File

@ -1,5 +1,3 @@
'use strict';
const Helpers = require('./Helpers');
/**

View File

@ -1,5 +1,3 @@
'use strict';
const fs = require('fs');
/**

View File

@ -1,5 +1,3 @@
'use strict';
const QueryBuilder = require('./QueryBuilder');
// Map config driver name to code class name

View File

@ -1,5 +1,3 @@
'use strict';
const Helpers = require('./Helpers');
const QueryBuilderBase = require('./QueryBuilderBase');

View File

@ -1,5 +1,3 @@
'use strict';
const Helpers = require('./Helpers');
const QueryParser = require('./QueryParser');
const State = require('./State');
@ -127,6 +125,10 @@ class QueryBuilderBase {
* when appending to state
*
* @private
* @param {mixed} letName Lorem Ipsum
* @param {mixed} valType Lorem Ipsum
* @param {mixed} key Lorem Ipsum
* @param {mixed} val Lorem Ipsum
* @return {Array} - modified state array
*/
_mixedSet (letName, valType, key, val) {

View File

@ -1,5 +1,3 @@
'use strict';
const XRegExp = require('xregexp');
const Helpers = require('./Helpers');
@ -35,7 +33,7 @@ class QueryParser {
${matchPatterns['function'].source}|
${matchPatterns.literal.source}
)
([a-z_\-]+[0-9]*\\.?)
([a-z_-]+[0-9]*\\.?)
)+`, 'igx');
// Full pattern for determining ordering of the pieces

View File

@ -1,5 +1,3 @@
'use strict';
const Helpers = require('./Helpers');
/**
@ -16,7 +14,7 @@ class Result {
* @param {Array} [rows] - the data rows of the result
* @param {Array} [columns] - the column names in the result
*/
constructor (rows=[], columns=[]) {
constructor (rows = [], columns = []) {
this._rows = rows;
this._columns = columns;

View File

@ -1,5 +1,3 @@
'use strict';
/**
* Class for objects containing the query builder state
* @private

View File

@ -1,8 +0,0 @@
'use strict';
const NodeFirebird = require('./node-firebird');
module.exports = config => {
return new NodeFirebird(config.connection);
};

View File

@ -1,61 +0,0 @@
'use strict';
const Adapter = require('../../Adapter');
const Result = require('../../Result');
const fb = require('node-firebird');
class Firebird extends Adapter {
constructor (config) {
super({});
this.instance = new Promise((resolve, reject) => {
fb.attach(config, (err, instance) => {
if (err) {
return reject(err);
}
return resolve(instance);
});
});
}
/**
* Run the sql query as a prepared statement
*
* @param {String} sql - The sql with placeholders
* @param {Array} params - The values to insert into the query
* @return {Promise} - Returns a promise if no callback is provided
*/
execute (sql, params) {
return this.instance.then(conn => {
return new Promise((resolve, reject) => {
conn.query(sql, params, (err, result) => {
if (err) {
return reject(err);
}
return resolve(this.transformResult(result));
});
});
});
}
/**
* Transform the adapter's result into a standard format
*
* @param {*} originalResult - the original result object from the driver
* @return {Result} - the new result object
*/
transformResult (originalResult) {
return new Result(originalResult);
}
/**
* Close the current database connection
* @return {void}
*/
close () {
this.instance.then(conn => conn.detach());
}
}
module.exports = Firebird;

View File

@ -1,3 +1 @@
'use strict';
module.exports = require('../Mysql');

View File

@ -1,5 +1,3 @@
'use strict';
const Mysql2 = require('./mysql2');
module.exports = config => {

View File

@ -1,12 +1,9 @@
'use strict';
const Adapter = require('../../Adapter');
const Result = require('../../Result');
const Helpers = require('../../Helpers');
const mysql2 = require('mysql2/promise');
class Mysql extends Adapter {
constructor (config) {
const instance = mysql2.createConnection(config);
super(instance);

View File

@ -1,5 +1,3 @@
'use strict';
const Adapter = require('../../Adapter');
const Result = require('../../Result');
const Helpers = require('../../Helpers');

View File

@ -1,9 +1,5 @@
'use strict';
const Pg = require('./Pg');
const Result = require('../../Result');
const pg = require('pg').native;
const url = require('url');
class PgNative extends Pg {
constructor (config) {
@ -21,7 +17,8 @@ class PgNative extends Pg {
instance = Promise.resolve(conn);
}
super(instance);
super.instance = instance;
}
}

View File

@ -1,7 +1,5 @@
'use strict';
const Pg = require('./Pg');
const PgNative = require('./PgNative')
const PgNative = require('./PgNative');
module.exports = config => {
return (config.native)

View File

@ -1,5 +1,3 @@
'use strict';
const Adapter = require('../../Adapter');
const Result = require('../../Result');
const Helpers = require('../../Helpers');

View File

@ -1,5 +1,3 @@
'use strict';
module.exports = config => {
const Implementation = (config.native)
? require('./sqlite3')
@ -7,4 +5,3 @@ module.exports = config => {
return new Implementation(config.connection);
};

View File

@ -1,5 +1,3 @@
'use strict';
const Adapter = require('../../Adapter');
const Result = require('../../Result');
const Helpers = require('../../Helpers');

View File

@ -1,45 +0,0 @@
'use strict';
let Helpers = require('../Helpers');
/**
* Driver for Firebird databases
*
* @module drivers/firebird
*/
module.exports = (() => {
delete require.cache[require.resolve('../Driver')];
let driver = require('../Driver');
driver.hasTruncate = false;
/**
* Set the limit clause
* @param {String} origSql - SQL statement to modify
* @param {Number} limit - Maximum number of rows to fetch
* @param {Number|null} offset - Number of rows to skip
* @return {String} - Modified SQL statement
*/
driver.limit = (origSql, limit, offset) => {
let sql = `FIRST ${limit}`;
if (Helpers.isNumber(offset)) {
sql += ` SKIP ${offset}`;
}
return origSql.replace(/SELECT/i, `SELECT ${sql}`);
};
/**
* SQL to insert a group of rows
*
* @return {void}
* @throws {Error}
*/
driver.insertBatch = () => {
throw new Error('Not Implemented');
};
return driver;
})();

View File

@ -1,5 +1,3 @@
'use strict';
/**
* Driver for MariaDB databases
*

View File

@ -1,5 +1,3 @@
'use strict';
/**
* Driver for MySQL databases
*

View File

@ -1,5 +1,3 @@
'use strict';
/**
* Driver for PostgreSQL databases
*

View File

@ -1,5 +1,3 @@
'use strict';
/**
* Driver for SQLite databases
*

View File

@ -1,96 +1,102 @@
{
"name": "ci-node-query",
"version": "5.0.0",
"description": "A query builder for node based on the one in CodeIgniter",
"author": "Timothy J Warren <tim@timshomepage.net>",
"engines": {
"node": ">=6.0.0"
},
"files": [
"lib/"
],
"contributors": [
{
"name": "Timothy J Warren",
"email": "tim@timshomepage.net"
}
],
"repository": {
"type": "git",
"url": "https://git.timshomepage.net/timw4mail/node-query.git"
},
"keywords": [
"codeigniter",
"mariadb",
"mysql",
"mssql",
"query builder",
"postgres",
"postgresql",
"sql",
"sqlite",
"sqlite3",
"sqlserver"
],
"bugs": {
"url": "https://git.timshomepage.net/timw4mail/node-query/issues"
},
"main": "lib/NodeQuery.js",
"dependencies": {
"dblite": "^0.7.8",
"getargs": "~0.0.8",
"glob": "^7.0.3",
"mysql2": "^1.2.0",
"node-firebird": "^0.8.1",
"pg": "^6.1.2",
"require-reload": "~0.2.2",
"sqlite3": "^3.1.8",
"tedious": "^1.14.0",
"xregexp": "^3.0.0"
},
"devDependencies": {
"chai": "^3.5.0",
"chai-as-promised": "^6.0.0",
"documentation": "latest",
"eslint": "^3.5.0",
"globstar": "^1.0.0",
"happiness": "^7.1.2",
"jest": "^19.0.2",
"jsdoc": "^3.4.3",
"npm-run-all": "^4.0.2",
"nsp": "^2.2.1"
},
"license": "MIT",
"jest": {
"coverageDirectory": "coverage",
"coverageReporters": [
"html",
"json",
"lcov",
"text-summary"
],
"testEnvironment": "node",
"testMatch": [
"**/test/**/*_test.js"
]
},
"scripts": {
"audit": "nsp check",
"build": "npm-run-all --parallel lint:src lint:tests docs coverage",
"coverage": "jest --coverage",
"default": "npm-run-all --parallel audit lint:src lint:tests && npm run test",
"predocs": "globstar -- documentation build -f md -o API.md \"lib/*.js\"",
"docs": "globstar -- documentation build -f html -o docs \"lib/*.js\"",
"postdocs": "jsdoc lib -r -d documentation",
"happy": "happiness \"lib/**/*.js\" \"test/**/*.js\"",
"happy:src": "happiness \"lib/**/*.js\"",
"happy:tests": "happiness \"test/**/*.js\"",
"lint": "npm-run-all lint:tests lint:src happy",
"lint:src": "eslint ./lib",
"lint:tests": "eslint ./test",
"test": "jest"
},
"peerDependencies": {
"pg-native": "^1.10.0"
}
"name": "ci-node-query",
"version": "6.0.0",
"description": "A query builder for node based on the one in CodeIgniter",
"author": "Timothy J Warren <tim@timshomepage.net>",
"engines": {
"node": ">=8.0.0"
},
"files": [
"lib/"
],
"contributors": [
{
"name": "Timothy J Warren",
"email": "tim@timshomepage.net"
}
],
"repository": {
"type": "git",
"url": "https://git.timshomepage.net/timw4mail/node-query.git"
},
"keywords": [
"codeigniter",
"mariadb",
"mysql",
"mssql",
"query builder",
"postgres",
"postgresql",
"sql",
"sqlite",
"sqlite3",
"sqlserver"
],
"bugs": {
"url": "https://git.timshomepage.net/timw4mail/node-query/issues"
},
"main": "lib/NodeQuery.js",
"dependencies": {
"dblite": "^0.8.0",
"getargs": "~0.0.8",
"glob": "^7.0.3",
"mysql2": "^1.2.0",
"pg": "^7.4",
"require-reload": "~0.2.2",
"sqlite3": "^3.1.8",
"tedious": "^2.0.0",
"xregexp": "^4.0.0"
},
"devDependencies": {
"babel-eslint": "^8.2.1",
"chai": "^4.1",
"chai-as-promised": "^7.1",
"documentation": "latest",
"eslint": "^4.16.0",
"globstar": "^1.0.0",
"happiness": "^10.0",
"jest": "^22.0.0",
"jsdoc": "^3.4.3",
"npm-run-all": "^4.0.2",
"nsp": "^3.1",
"pg-native": "^2.2"
},
"license": "MIT",
"jest": {
"coverageDirectory": "coverage",
"coverageReporters": [
"html",
"json",
"lcov",
"text-summary"
],
"testEnvironment": "node",
"testMatch": [
"**/test/**/*_test.js"
]
},
"scripts": {
"audit": "nsp check",
"build": "npm-run-all --parallel lint:src lint:tests docs coverage",
"coverage": "jest --coverage",
"default": "npm-run-all --parallel audit lint:src lint:tests && npm run test",
"predocs": "globstar -- documentation build -f md -o API.md \"lib/*.js\"",
"docs": "globstar -- documentation build -f html -o docs \"lib/*.js\"",
"fix": "happiness --fix \"lib/**/*.js\" \"test/**/*.js\"",
"postdocs": "jsdoc lib -r -d documentation",
"happy": "happiness \"lib/**/*.js\" \"test/**/*.js\"",
"happy:src": "happiness \"lib/**/*.js\"",
"happy:tests": "happiness \"test/**/*.js\"",
"lint": "npm-run-all lint:tests lint:src happy",
"lint:src": "eslint ./lib",
"lint:tests": "eslint ./test",
"test": "jest"
},
"happiness": {
"env": {
"es6": true,
"jest": true
},
"parser": "babel-eslint"
}
}

Binary file not shown.

View File

@ -1,11 +1,7 @@
/* eslint-env node, mocha */
'use strict';
// Load the test base
const reload = require('require-reload')(require);
reload.emptyCache();
const testBase = reload('../base');
const expect = testBase.expect;
const testRunner = testBase.promiseTestRunner;
// Load the test config file
@ -23,15 +19,15 @@ describe('Dblite adapter tests -', () => {
});
testRunner(qb);
it('Promise - Select with function and argument in WHERE clause', () => {
let promise = qb.select('id')
it('Promise - Select with function and argument in WHERE clause', async () => {
let promise = await qb.select('id')
.from('create_test')
.where('id', 'ABS(-88)')
.get();
expect(promise).to.be.fulfilled;
expect(promise).toEqual(expect.anything());
});
it('Promise - Test Insert Batch', () => {
it('Promise - Test Insert Batch', async () => {
let data = [
{
id: 544,
@ -48,8 +44,8 @@ describe('Dblite adapter tests -', () => {
}
];
let promise = qb.insertBatch('create_test', data);
expect(promise).to.be.fulfilled;
let promise = await qb.insertBatch('create_test', data);
expect(promise).toEqual(expect.anything());
});
afterAll(() => {
qb.end();

View File

@ -1,11 +1,7 @@
/* eslint-env node, mocha */
'use strict';
// Load the test base
const reload = require('require-reload')(require);
reload.emptyCache();
const testBase = reload('../base');
const expect = testBase.expect;
const testRunner = testBase.promiseTestRunner;
// Load the test config file
@ -24,24 +20,23 @@ describe('Mysql2 adapter tests -', () => {
});
it('nodeQuery.getQuery = nodeQuery.init', () => {
expect(nodeQuery.getQuery())
.to.be.deep.equal(qb);
expect(nodeQuery.getQuery()).toEqual(qb);
});
testRunner(qb);
it('Promise - Select with function and argument in WHERE clause', () => {
let promise = qb.select('id')
it('Promise - Select with function and argument in WHERE clause', async () => {
let promise = await qb.select('id')
.from('create_test')
.where('id', 'CEILING(SQRT(88))')
.get();
return expect(promise).to.be.fulfilled;
expect(promise).toEqual(expect.anything());
});
it('Test Truncate', () => {
let promise = qb.truncate('create_test');
return expect(promise).to.be.fullfilled;
it('Test Truncate', async () => {
let promise = await qb.truncate('create_test');
expect(promise).toEqual(expect.anything());
});
it('Test Insert Batch', () => {
it('Test Insert Batch', async () => {
let data = [
{
id: 5442,
@ -58,7 +53,8 @@ describe('Mysql2 adapter tests -', () => {
}
];
return expect(qb.insertBatch('create_test', data)).to.be.fulfilled;
const promise = await qb.insertBatch('create_test', data);
expect(promise).toEqual(expect.anything());
});
/* describeTeardown(() => {

View File

@ -1,38 +0,0 @@
/* eslint-env node, mocha */
'use strict';
// Load the test base
const path = require('path');
const reload = require('require-reload')(require);
const testBase = reload('../base');
const expect = testBase.expect;
const testRunner = testBase.promiseTestRunner;
// Skip on CI
if (!(process.env.CI || process.env.TRAVIS)) {
// Load the test config file
let adapterName = 'node-firebird';
const config = reload('../config.json')[adapterName];
config.connection.database = path.join(__dirname, config.connection.database);
let nodeQuery = reload('../../lib/NodeQuery')(config);
let qb = nodeQuery.getQuery();
describe('Firebird adapter tests -', () => {
it('nodeQuery.getQuery = nodeQuery.init', () => {
expect(nodeQuery.getQuery())
.to.be.deep.equal(qb);
});
it('insertBatch throws error', () => {
expect(() => {
qb.driver.insertBatch('create_test', []);
}).to.throw(Error, 'Not Implemented');
});
testRunner(qb);
afterAll(() => {
qb.end();
});
});
}

View File

@ -1,11 +1,7 @@
/* eslint-env node, mocha */
'use strict';
// Load the test base
const reload = require('require-reload')(require);
reload.emptyCache();
const testBase = reload('../base');
const expect = testBase.expect;
const testRunner = testBase.promiseTestRunner;
// Load the test config file
@ -27,7 +23,7 @@ describe('Pg adapter tests -', () => {
it('nodeQuery.getQuery = nodeQuery.init', () => {
expect(nodeQuery.getQuery())
.to.be.deep.equal(qb);
.toEqual(qb);
});
it('Connecting with an object also works', () => {
@ -35,7 +31,7 @@ describe('Pg adapter tests -', () => {
let nodeQuery = reload('../../lib/NodeQuery')(config);
qb2 = nodeQuery.getQuery();
expect(qb2).to.be.ok;
expect(qb2).toEqual(expect.anything());
});
it('Test Connection Error', done => {
@ -43,26 +39,25 @@ describe('Pg adapter tests -', () => {
reload('../../lib/NodeQuery')({});
done(true);
} catch (e) {
expect(e).to.be.ok;
expect(e).is.an('Error');
expect(e).toEqual(expect.anything());
done();
}
});
testRunner(qb);
it('Promise - Select with function and argument in WHERE clause', () => {
let promise = qb.select('id')
it('Promise - Select with function and argument in WHERE clause', async () => {
let promise = await qb.select('id')
.from('create_test')
.where('id', 'CEILING(SQRT(88))')
.get();
return expect(promise).to.be.fulfilled;
expect(promise).toEqual(expect.anything());
});
it('Promise - Test Truncate', () => {
let promise = qb.truncate('create_test');
return expect(promise).to.be.fulfilled;
it('Promise - Test Truncate', async () => {
let promise = await qb.truncate('create_test');
expect(promise).toEqual(expect.anything());
});
it('Promise - Test Insert Batch', () => {
it('Promise - Test Insert Batch', async () => {
let data = [
{
id: 544,
@ -79,8 +74,8 @@ describe('Pg adapter tests -', () => {
}
];
let promise = qb.insertBatch('create_test', data);
return expect(promise).to.be.fulfilled;
let promise = await qb.insertBatch('create_test', data);
expect(promise).toEqual(expect.anything());
});
afterAll(() => {
qb.end();

View File

@ -1,11 +1,7 @@
/* eslint-env node, mocha */
'use strict';
// Load the test base
const reload = require('require-reload')(require);
reload.emptyCache();
const testBase = reload('../base');
const expect = testBase.expect;
const testRunner = testBase.promiseTestRunner;
// Load the test config file
@ -24,15 +20,15 @@ describe('Sqlite3 adapter tests -', () => {
});
testRunner(qb);
it('Promise - Select with function and argument in WHERE clause', () => {
let promise = qb.select('id')
it('Promise - Select with function and argument in WHERE clause', async () => {
let promise = await qb.select('id')
.from('create_test')
.where('id', 'ABS(-88)')
.get();
expect(promise).to.be.fulfilled;
expect(promise).toEqual(expect.anything());
});
it('Promise - Test Insert Batch', () => {
it('Promise - Test Insert Batch', async () => {
let data = [
{
id: 544,
@ -49,8 +45,8 @@ describe('Sqlite3 adapter tests -', () => {
}
];
let promise = qb.insertBatch('create_test', data);
expect(promise).to.be.fulfilled;
let promise = await qb.insertBatch('create_test', data);
expect(promise).toEqual(expect.anything());
});
afterAll(() => {
qb.end();

View File

@ -1,5 +1,3 @@
'use strict';
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);

View File

@ -1,18 +1,10 @@
/* eslint-env node, mocha */
'use strict';
// Load the test base
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
const expect = chai.expect;
const reload = require('require-reload')(require);
const tests = reload('../base/tests');
module.exports = function promiseTestRunner (qb) {
Object.keys(tests).forEach(describeName => {
describe(describeName, () => {
describe(describeName, async () => {
let currentSuite = tests[describeName];
Object.keys(currentSuite).forEach(testDesc => {
it(testDesc, done => {
@ -34,94 +26,94 @@ module.exports = function promiseTestRunner (qb) {
}
});
let promise = results.pop();
const promise = results.pop();
promise.then(result => {
expect(result.rows).is.an('array');
expect(result.rowCount()).to.not.be.undefined;
expect(result.columnCount()).to.not.be.undefined;
// expect(result.rows).is.an('array');
expect(result.rowCount()).toEqual(expect.anything());
expect(result.columnCount()).toEqual(expect.anything());
return done();
}).catch(e => done(e));
});
});
});
});
describe('DB update tests -', () => {
describe('DB update tests -', async () => {
beforeAll(done => {
let sql = qb.driver.truncate('create_test');
qb.query(sql).then(res => done())
.catch(err => done(err));
});
it('Promise - Test Insert', () => {
let promise = qb.set('id', 98)
it('Promise - Test Insert', async () => {
const promise = await qb.set('id', 98)
.set('key', '84')
.set('val', Buffer.from('120'))
.insert('create_test');
return expect(promise).to.be.fulfilled;
expect(promise).toEqual(expect.anything());
});
it('Promise - Test Insert Object', () => {
let promise = qb.insert('create_test', {
it('Promise - Test Insert Object', async () => {
const promise = await qb.insert('create_test', {
id: 587,
key: 1,
val: Buffer.from('2')
});
return expect(promise).to.be.fulfilled;
expect(promise).toEqual(expect.anything());
});
it('Promise - Test Update', () => {
let promise = qb.where('id', 7)
it('Promise - Test Update', async () => {
const promise = await qb.where('id', 7)
.update('create_test', {
id: 7,
key: 'gogle',
val: Buffer.from('non-word')
});
return expect(promise).to.be.fulfilled;
expect(promise).toEqual(expect.anything());
});
it('Promise - Test set Array Update', () => {
it('Promise - Test set Array Update', async () => {
let object = {
id: 22,
key: 'gogle',
val: Buffer.from('non-word')
};
let promise = qb.set(object)
const promise = await qb.set(object)
.where('id', 22)
.update('create_test');
return expect(promise).to.be.fulfilled;
expect(promise).toEqual(expect.anything());
});
it('Promise - Test where set update', () => {
let promise = qb.where('id', 36)
it('Promise - Test where set update', async () => {
const promise = await qb.where('id', 36)
.set('id', 36)
.set('key', 'gogle')
.set('val', Buffer.from('non-word'))
.update('create_test');
return expect(promise).to.be.fulfilled;
expect(promise).toEqual(expect.anything());
});
it('Promise - Test delete', () => {
let promise = qb.delete('create_test', {id: 5});
return expect(promise).to.be.fulfilled;
it('Promise - Test delete', async () => {
const promise = await qb.delete('create_test', {id: 5});
expect(promise).toEqual(expect.anything());
});
it('Promise - Delete with where', () => {
let promise = qb.where('id', 5)
it('Promise - Delete with where', async () => {
const promise = await qb.where('id', 5)
.delete('create_test');
return expect(promise).to.be.fulfilled;
expect(promise).toEqual(expect.anything());
});
it('Promise - Delete multiple where values', () => {
let promise = qb.delete('create_test', {
it('Promise - Delete multiple where values', async () => {
const promise = await qb.delete('create_test', {
id: 5,
key: 'gogle'
});
return expect(promise).to.be.fulfilled;
expect(promise).toEqual(expect.anything());
});
});
describe('Grouping tests -', () => {
it('Promise - Using grouping method', () => {
let promise = qb.select('id, key as k, val')
describe('Grouping tests -', async () => {
it('Promise - Using grouping method', async () => {
const promise = await qb.select('id, key as k, val')
.from('create_test')
.groupStart()
.where('id >', 1)
@ -130,10 +122,10 @@ module.exports = function promiseTestRunner (qb) {
.limit(2, 1)
.get();
return expect(promise).to.be.fulfilled;
expect(promise).toEqual(expect.anything());
});
it('Promise - Using where first grouping', () => {
let promise = qb.select('id, key as k, val')
it('Promise - Using where first grouping', async () => {
const promise = await qb.select('id, key as k, val')
.from('create_test')
.where('id !=', 5)
.groupStart()
@ -143,10 +135,10 @@ module.exports = function promiseTestRunner (qb) {
.limit(2, 1)
.get();
return expect(promise).to.be.fulfilled;
expect(promise).toEqual(expect.anything());
});
it('Promise - Using or grouping method', () => {
let promise = qb.select('id, key as k, val')
it('Promise - Using or grouping method', async () => {
const promise = await qb.select('id, key as k, val')
.from('create_test')
.groupStart()
.where('id >', 1)
@ -158,10 +150,10 @@ module.exports = function promiseTestRunner (qb) {
.limit(2, 1)
.get();
return expect(promise).to.be.fulfilled;
expect(promise).toEqual(expect.anything());
});
it('Promise - Using or not grouping method', () => {
let promise = qb.select('id, key as k, val')
it('Promise - Using or not grouping method', async () => {
const promise = await qb.select('id, key as k, val')
.from('create_test')
.groupStart()
.where('id >', 1)
@ -173,7 +165,7 @@ module.exports = function promiseTestRunner (qb) {
.limit(2, 1)
.get();
return expect(promise).to.be.fulfilled;
expect(promise).toEqual(expect.anything());
});
});
};

View File

@ -1,5 +1,3 @@
'use strict';
module.exports = {
'Get tests -': {
'Get with function': {

View File

@ -1,7 +1,3 @@
/* eslint-env node, mocha */
'use strict';
const expect = require('chai').expect;
const reload = require('require-reload')(require);
const glob = require('glob');
const nodeQuery = reload('../lib/NodeQuery')();
@ -14,7 +10,7 @@ describe('Base tests -', () => {
let obj = require(mod);
let shortName = mod.replace(/^\/(.*?)\/lib\/(.*?)\.js$/g, '$2');
it(`${shortName} module is sane`, () => {
expect(obj).to.be.ok;
expect(obj).toEqual(expect.anything());
});
});
});
@ -26,7 +22,7 @@ describe('Base tests -', () => {
nodeQueryCopy.instance = null;
expect(() => {
nodeQueryCopy.getQuery();
}).to.throw(Error, 'No Query Builder instance to return');
}).toThrow(Error, 'No Query Builder instance to return');
});
it('Invalid driver type', () => {
@ -34,20 +30,20 @@ describe('Base tests -', () => {
reload('../lib/NodeQuery')({
driver: 'Foo'
});
}).to.throw(Error, 'Selected driver (Foo) does not exist!');
}).toThrow(Error, 'Selected driver (Foo) does not exist!');
});
it('Invalid adapter', () => {
expect(() => {
let a = new Adapter();
a.execute();
}).to.throw(Error, 'Correct adapter not defined for query execution');
}).toThrow(Error, 'Correct adapter not defined for query execution');
});
it('Invalid adapter - missing transformResult', () => {
expect(() => {
let a = new Adapter();
a.transformResult([]);
}).to.throw(Error, 'Result transformer method not defined for current adapter');
}).toThrow(Error, 'Result transformer method not defined for current adapter');
});
});

View File

@ -1,26 +1,19 @@
/* eslint-env node, mocha */
'use strict';
const chai = require('chai');
const assert = chai.assert;
const expect = chai.expect;
let Helpers = require('../lib/Helpers');
const Helpers = require('../lib/Helpers');
describe('Helper Module Tests -', () => {
describe('Type-checking methods -', () => {
describe('Object wrappers are listed as their native type', () => {
it('Boolean Wrapper returns \'boolean\' not \'object\'', () => {
let item = Boolean(true);
expect(Helpers.type(item)).to.deep.equal('boolean');
expect(Helpers.type(item)).toEqual('boolean');
});
it('Number Wrapper returns \'number\' not \'object\'', () => {
let item = Number(4867);
expect(Helpers.type(item)).to.deep.equal('number');
expect(Helpers.type(item)).toEqual('number');
});
it('String Wrapper returns \'string\' not \'object\'', () => {
let item = String('Foo');
expect(Helpers.type(item)).to.deep.equal('string');
expect(Helpers.type(item)).toEqual('string');
});
});
describe('is..Method methods exist -', () => {
@ -40,7 +33,7 @@ describe('Helper Module Tests -', () => {
types.forEach(type => {
it(`is${type} method exists`, () => {
assert.ok(Helpers[`is${type}`]);
expect(Helpers[`is${type}`]).toBeDefined();
});
});
});
@ -52,7 +45,7 @@ describe('Helper Module Tests -', () => {
};
Object.keys(trueCases).forEach(desc => {
it(desc, () => {
expect(Helpers.isScalar(trueCases[desc])).to.be.true;
expect(Helpers.isScalar(trueCases[desc])).toBe(true);
});
});
@ -62,24 +55,24 @@ describe('Helper Module Tests -', () => {
};
Object.keys(falseCases).forEach(desc => {
it(desc, () => {
expect(Helpers.isScalar(falseCases[desc])).to.be.false;
expect(Helpers.isScalar(falseCases[desc])).toBe(false);
});
});
});
describe('isInfinity -', () => {
it('The type of 1/0 is infinity', () => {
expect(Helpers.type(1 / 0)).to.equal('infinity');
expect(Helpers.type(1 / 0)).toBe('infinity');
});
it('isInfinity is the same as isInfinite', () => {
expect(Helpers.isInfinite(1 / 0)).to.be.true;
expect(Helpers.isInfinite(1 / 0)).toBe(true);
});
});
describe('isNaN -', () => {
it('The type of 0 / 0 is NaN', () => {
expect(Helpers.type(0 / 0)).to.equal('nan');
expect(Helpers.type(0 / 0)).toBe('nan');
});
it('isNaN method agrees with type', () => {
expect(Helpers.isNaN(0 / 0)).to.be.true;
expect(Helpers.isNaN(0 / 0)).toBe(true);
});
});
});
@ -89,7 +82,7 @@ describe('Helper Module Tests -', () => {
let orig = [' x y ', 'z ', ' q'];
let ret = ['x y', 'z', 'q'];
expect(orig.map(Helpers.stringTrim)).to.be.deep.equal(ret);
expect(orig.map(Helpers.stringTrim)).toEqual(ret);
});
});
describe('arrayPluck -', () => {
@ -106,13 +99,13 @@ describe('Helper Module Tests -', () => {
];
it('Finding members in all objects', () => {
expect(Helpers.arrayPluck(orig, 'foo')).to.be.deep.equal([1, 2, 3]);
expect(Helpers.arrayPluck(orig, 'foo')).toEqual([1, 2, 3]);
});
it('Some members are missing in some objects', () => {
expect(Helpers.arrayPluck(orig, 'bar')).to.be.deep.equal([10, 15]);
expect(Helpers.arrayPluck(orig, 'bar')).toEqual([10, 15]);
});
it('Empty case', () => {
expect(Helpers.arrayPluck([], 'apple')).to.be.deep.equal([]);
expect(Helpers.arrayPluck([], 'apple')).toEqual([]);
});
});
describe('regexInArray -', () => {
@ -133,25 +126,25 @@ describe('Helper Module Tests -', () => {
Object.keys(boolCase).forEach(desc => {
it(desc, () => {
if (i) {
expect(Helpers.regexInArray(orig, boolCase[desc])).to.be.true;
expect(Helpers.regexInArray(orig, boolCase[desc])).toBe(true);
} else {
expect(Helpers.regexInArray(orig, boolCase[desc])).to.be.false;
expect(Helpers.regexInArray(orig, boolCase[desc])).toBe(false);
}
});
});
});
it('First argument is not an array', () => {
expect(Helpers.regexInArray(5, /5/)).to.be.false;
expect(Helpers.regexInArray(5, /5/)).toBe(false);
});
it('Array is empty', () => {
expect(Helpers.regexInArray([], /.*/)).to.be.false;
expect(Helpers.regexInArray([], /.*/)).toBe(false);
});
});
describe('upperCaseFirst -', () => {
it('Capitalizes only the first letter of the string', () => {
expect(Helpers.upperCaseFirst('foobar')).to.equal('Foobar');
expect(Helpers.upperCaseFirst('FOOBAR')).to.equal('FOOBAR');
expect(Helpers.upperCaseFirst('foobar')).toBe('Foobar');
expect(Helpers.upperCaseFirst('FOOBAR')).toBe('FOOBAR');
});
});
});

View File

@ -1,7 +1,3 @@
/* eslint-env node, mocha */
'use strict';
const expect = require('chai').expect;
// Use the base driver as a mock for testing
const Helpers = require('../lib/Helpers');
const driver = require('../lib/Driver');
@ -56,11 +52,11 @@ describe('Query Parser Tests', () => {
describe('Has operator tests', () => {
it('Has operator', () => {
let matches = parser.hasOperator('foo <> 2');
expect(matches).to.be.deep.equal(['<>']);
expect(matches).toEqual(['<>']);
});
it('Has no operator', () => {
let matches = parser.hasOperator('foo');
expect(matches).to.be.null;
expect(matches).toBe(null);
});
});
describe('Where parser tests', () => {
@ -71,13 +67,13 @@ describe('Query Parser Tests', () => {
whereMock('time < SUM(FOO(BAR()))');
parser.parseWhere(driver, state);
expect(state.whereMap)
.to.be.deep.equal(['"time" < SUM(FOO(BAR()))']);
.toEqual(['"time" < SUM(FOO(BAR()))']);
});
it('Has function key/val', () => {
whereMock('time <', 'SUM(FOO(BAR()))');
parser.parseWhere(driver, state);
expect(state.whereMap)
.to.be.deep.equal(['"time" < SUM(FOO(BAR()))']);
.toEqual(['"time" < SUM(FOO(BAR()))']);
});
<