From mocha to jest

This commit is contained in:
Timothy Warren 2017-02-28 15:47:29 -05:00
parent ad91099706
commit cdc5dcfa17
14 changed files with 120 additions and 118 deletions

View File

@ -1,9 +0,0 @@
reporting:
print: summary
reports:
- lcov
- lcovonly
- clover
- html
- text
dir: ./coverage

View File

@ -52,25 +52,37 @@
"eslint": "^3.5.0", "eslint": "^3.5.0",
"globstar": "^1.0.0", "globstar": "^1.0.0",
"happiness": "^7.1.2", "happiness": "^7.1.2",
"istanbul": "~0.4.2", "jest": "^19.0.2",
"mocha": "^3.0.0",
"npm-run-all": "^3.0.0", "npm-run-all": "^3.0.0",
"nsp": "^2.2.1" "nsp": "^2.2.1"
}, },
"license": "MIT", "license": "MIT",
"jest": {
"coverageDirectory": "coverage",
"coverageReporters": [
"html",
"json",
"lcov",
"text-summary"
],
"testEnvironment": "node",
"testMatch": [
"**/test/**/*_test.js"
]
},
"scripts": { "scripts": {
"audit": "nsp check", "audit": "nsp check",
"build": "npm-run-all --parallel lint:src lint:tests docs coverage", "build": "npm-run-all --parallel lint:src lint:tests docs coverage",
"coverage": "istanbul cover ./node_modules/mocha/bin/_mocha", "coverage": "jest --coverage",
"default": "npm-run-all --parallel audit lint:src lint:tests && npm run test", "default": "npm-run-all --parallel audit lint:src lint:tests && npm run test",
"predocs": "globstar -- documentation build -f md -o API.md \"lib/*.js\"", "predocs": "globstar -- documentation build -f md -o API.md \"lib/*.js\"",
"docs": "globstar -- documentation build -f html -o docs \"lib/*.js\"", "docs": "globstar -- documentation build -f html -o docs \"lib/*.js\"",
"happy": "happiness \"lib/**/*.js\" \"test/**/*.js\"", "happy": "happiness \"lib/**/*.js\" \"test/**/*.js\"",
"happy:src": "happiness \"lib/**/*.js\"", "happy:src": "happiness \"lib/**/*.js\"",
"happy:tests": "happiness \"test/**/*.js\"", "happy:tests": "happiness \"test/**/*.js\"",
"lint": "npm-run-all lint:tests lint:src && happy", "lint": "npm-run-all lint:tests lint:src happy",
"lint:src": "eslint ./lib", "lint:src": "eslint ./lib",
"lint:tests": "eslint ./test", "lint:tests": "eslint ./test",
"test": "mocha -R spec" "test": "jest"
} }
} }

Binary file not shown.

View File

@ -15,8 +15,8 @@ const config = testBase.config;
let nodeQuery = require('../../lib/NodeQuery')(config.dblite); let nodeQuery = require('../../lib/NodeQuery')(config.dblite);
let qb = nodeQuery.getQuery(); let qb = nodeQuery.getQuery();
suite('Dblite adapter tests -', () => { describe('Dblite adapter tests -', () => {
suiteSetup(done => { beforeAll(done => {
// Set up the sqlite database // Set up the sqlite database
const createTest = 'CREATE TABLE IF NOT EXISTS "create_test" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);'; const createTest = 'CREATE TABLE IF NOT EXISTS "create_test" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);';
const createJoin = 'CREATE TABLE IF NOT EXISTS "create_join" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);'; const createJoin = 'CREATE TABLE IF NOT EXISTS "create_join" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);';
@ -29,7 +29,7 @@ suite('Dblite adapter tests -', () => {
}); });
testRunner(qb); testRunner(qb);
test('Promise - Select with function and argument in WHERE clause', () => { it('Promise - Select with function and argument in WHERE clause', () => {
let promise = qb.select('id') let promise = qb.select('id')
.from('create_test') .from('create_test')
.where('id', 'ABS(-88)') .where('id', 'ABS(-88)')
@ -37,7 +37,7 @@ suite('Dblite adapter tests -', () => {
expect(promise).to.be.fulfilled; expect(promise).to.be.fulfilled;
}); });
test('Promise - Test Insert Batch', () => { it('Promise - Test Insert Batch', () => {
let data = [ let data = [
{ {
id: 544, id: 544,
@ -57,7 +57,7 @@ suite('Dblite adapter tests -', () => {
let promise = qb.insertBatch('create_test', data); let promise = qb.insertBatch('create_test', data);
expect(promise).to.be.fulfilled; expect(promise).to.be.fulfilled;
}); });
suiteTeardown(() => { afterAll(() => {
qb.end(); qb.end();
}); });
}); });

View File

@ -16,14 +16,14 @@ const config = testBase.config[adapterName];
let nodeQuery = reload('../../lib/NodeQuery')(config); let nodeQuery = reload('../../lib/NodeQuery')(config);
let qb = nodeQuery.getQuery(); let qb = nodeQuery.getQuery();
suite('Mysql2 adapter tests -', () => { describe('Mysql2 adapter tests -', () => {
test('nodeQuery.getQuery = nodeQuery.init', () => { it('nodeQuery.getQuery = nodeQuery.init', () => {
expect(nodeQuery.getQuery()) expect(nodeQuery.getQuery())
.to.be.deep.equal(qb); .to.be.deep.equal(qb);
}); });
testRunner(qb); testRunner(qb);
test('Promise - Select with function and argument in WHERE clause', () => { it('Promise - Select with function and argument in WHERE clause', () => {
let promise = qb.select('id') let promise = qb.select('id')
.from('create_test') .from('create_test')
.where('id', 'CEILING(SQRT(88))') .where('id', 'CEILING(SQRT(88))')
@ -31,11 +31,11 @@ suite('Mysql2 adapter tests -', () => {
return expect(promise).to.be.fulfilled; return expect(promise).to.be.fulfilled;
}); });
test('Test Truncate', () => { it('Test Truncate', () => {
let promise = qb.truncate('create_test'); let promise = qb.truncate('create_test');
return expect(promise).to.be.fullfilled; return expect(promise).to.be.fullfilled;
}); });
test('Test Insert Batch', () => { it('Test Insert Batch', () => {
let data = [ let data = [
{ {
id: 5442, id: 5442,
@ -55,7 +55,7 @@ suite('Mysql2 adapter tests -', () => {
return expect(qb.insertBatch('create_test', data)).to.be.fulfilled; return expect(qb.insertBatch('create_test', data)).to.be.fulfilled;
}); });
/* suiteTeardown(() => { /* describeTeardown(() => {
qb.end(); qb.end();
}); */ }); */
}); });

View File

@ -18,12 +18,12 @@ if (!(process.env.CI || process.env.TRAVIS)) {
let qb = nodeQuery.getQuery(); let qb = nodeQuery.getQuery();
suite('Firebird adapter tests -', () => { describe('Firebird adapter tests -', () => {
test('nodeQuery.getQuery = nodeQuery.init', () => { it('nodeQuery.getQuery = nodeQuery.init', () => {
expect(nodeQuery.getQuery()) expect(nodeQuery.getQuery())
.to.be.deep.equal(qb); .to.be.deep.equal(qb);
}); });
test('insertBatch throws error', () => { it('insertBatch throws error', () => {
expect(() => { expect(() => {
qb.driver.insertBatch('create_test', []); qb.driver.insertBatch('create_test', []);
}).to.throw(Error, 'Not Implemented'); }).to.throw(Error, 'Not Implemented');
@ -31,7 +31,7 @@ if (!(process.env.CI || process.env.TRAVIS)) {
testRunner(qb); testRunner(qb);
suiteTeardown(() => { afterAll(() => {
qb.end(); qb.end();
}); });
}); });

View File

@ -18,21 +18,21 @@ let nodeQuery = reload('../../lib/NodeQuery')(config);
let qb = nodeQuery.getQuery(); let qb = nodeQuery.getQuery();
let qb2 = null; let qb2 = null;
suite('Pg adapter tests -', () => { describe('Pg adapter tests -', () => {
test('nodeQuery.getQuery = nodeQuery.init', () => { it('nodeQuery.getQuery = nodeQuery.init', () => {
expect(nodeQuery.getQuery()) expect(nodeQuery.getQuery())
.to.be.deep.equal(qb); .to.be.deep.equal(qb);
}); });
test('Connecting with an object also works', () => { it('Connecting with an object also works', () => {
let config = allConfig[`${adapterName}-object`]; let config = allConfig[`${adapterName}-object`];
let nodeQuery = reload('../../lib/NodeQuery')(config); let nodeQuery = reload('../../lib/NodeQuery')(config);
qb2 = nodeQuery.getQuery(); qb2 = nodeQuery.getQuery();
return expect(qb2).to.be.ok; expect(qb2).to.be.ok;
}); });
test('Test Connection Error', done => { it('Test Connection Error', done => {
try { try {
reload('../../lib/NodeQuery')({}); reload('../../lib/NodeQuery')({});
done(true); done(true);
@ -44,7 +44,7 @@ suite('Pg adapter tests -', () => {
}); });
testRunner(qb); testRunner(qb);
test('Promise - Select with function and argument in WHERE clause', () => { it('Promise - Select with function and argument in WHERE clause', () => {
let promise = qb.select('id') let promise = qb.select('id')
.from('create_test') .from('create_test')
.where('id', 'CEILING(SQRT(88))') .where('id', 'CEILING(SQRT(88))')
@ -52,11 +52,11 @@ suite('Pg adapter tests -', () => {
return expect(promise).to.be.fulfilled; return expect(promise).to.be.fulfilled;
}); });
test('Promise - Test Truncate', () => { it('Promise - Test Truncate', () => {
let promise = qb.truncate('create_test'); let promise = qb.truncate('create_test');
return expect(promise).to.be.fulfilled; return expect(promise).to.be.fulfilled;
}); });
test('Promise - Test Insert Batch', () => { it('Promise - Test Insert Batch', () => {
let data = [ let data = [
{ {
id: 544, id: 544,
@ -76,7 +76,7 @@ suite('Pg adapter tests -', () => {
let promise = qb.insertBatch('create_test', data); let promise = qb.insertBatch('create_test', data);
return expect(promise).to.be.fulfilled; return expect(promise).to.be.fulfilled;
}); });
suiteTeardown(() => { afterAll(() => {
qb.end(); qb.end();
qb2.end(); qb2.end();
}); });

View File

@ -15,8 +15,8 @@ const config = testBase.config;
let nodeQuery = require('../../lib/NodeQuery')(config.sqlite3); let nodeQuery = require('../../lib/NodeQuery')(config.sqlite3);
let qb = nodeQuery.getQuery(); let qb = nodeQuery.getQuery();
suite('Sqlite3 adapter tests -', () => { describe('Sqlite3 adapter tests -', () => {
suiteSetup(done => { beforeAll(done => {
// Set up the sqlite database // Set up the sqlite database
const createTest = 'CREATE TABLE IF NOT EXISTS "create_test" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);'; const createTest = 'CREATE TABLE IF NOT EXISTS "create_test" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);';
const createJoin = 'CREATE TABLE IF NOT EXISTS "create_join" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);'; const createJoin = 'CREATE TABLE IF NOT EXISTS "create_join" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);';
@ -29,7 +29,7 @@ suite('Sqlite3 adapter tests -', () => {
}); });
testRunner(qb); testRunner(qb);
test('Promise - Select with function and argument in WHERE clause', () => { it('Promise - Select with function and argument in WHERE clause', () => {
let promise = qb.select('id') let promise = qb.select('id')
.from('create_test') .from('create_test')
.where('id', 'ABS(-88)') .where('id', 'ABS(-88)')
@ -37,7 +37,7 @@ suite('Sqlite3 adapter tests -', () => {
expect(promise).to.be.fulfilled; expect(promise).to.be.fulfilled;
}); });
test('Promise - Test Insert Batch', () => { it('Promise - Test Insert Batch', () => {
let data = [ let data = [
{ {
id: 544, id: 544,
@ -57,7 +57,7 @@ suite('Sqlite3 adapter tests -', () => {
let promise = qb.insertBatch('create_test', data); let promise = qb.insertBatch('create_test', data);
expect(promise).to.be.fulfilled; expect(promise).to.be.fulfilled;
}); });
suiteTeardown(() => { afterAll(() => {
qb.end(); qb.end();
}); });
}); });

View File

@ -11,11 +11,11 @@ const reload = require('require-reload')(require);
const tests = reload('../base/tests'); const tests = reload('../base/tests');
module.exports = function promiseTestRunner (qb) { module.exports = function promiseTestRunner (qb) {
Object.keys(tests).forEach(suiteName => { Object.keys(tests).forEach(describeName => {
suite(suiteName, () => { describe(describeName, () => {
let currentSuite = tests[suiteName]; let currentSuite = tests[describeName];
Object.keys(currentSuite).forEach(testDesc => { Object.keys(currentSuite).forEach(testDesc => {
test(testDesc, done => { it(testDesc, done => {
const methodObj = currentSuite[testDesc]; const methodObj = currentSuite[testDesc];
const methodNames = Object.keys(methodObj); const methodNames = Object.keys(methodObj);
let results = []; let results = [];
@ -45,13 +45,13 @@ module.exports = function promiseTestRunner (qb) {
}); });
}); });
}); });
suite('DB update tests -', () => { describe('DB update tests -', () => {
suiteSetup(done => { beforeAll(done => {
let sql = qb.driver.truncate('create_test'); let sql = qb.driver.truncate('create_test');
qb.query(sql).then(res => done()) qb.query(sql).then(res => done())
.catch(err => done(err)); .catch(err => done(err));
}); });
test('Promise - Test Insert', () => { it('Promise - Test Insert', () => {
let promise = qb.set('id', 98) let promise = qb.set('id', 98)
.set('key', '84') .set('key', '84')
.set('val', Buffer.from('120')) .set('val', Buffer.from('120'))
@ -59,7 +59,7 @@ module.exports = function promiseTestRunner (qb) {
return expect(promise).to.be.fulfilled; return expect(promise).to.be.fulfilled;
}); });
test('Promise - Test Insert Object', () => { it('Promise - Test Insert Object', () => {
let promise = qb.insert('create_test', { let promise = qb.insert('create_test', {
id: 587, id: 587,
key: 1, key: 1,
@ -68,7 +68,7 @@ module.exports = function promiseTestRunner (qb) {
return expect(promise).to.be.fulfilled; return expect(promise).to.be.fulfilled;
}); });
test('Promise - Test Update', () => { it('Promise - Test Update', () => {
let promise = qb.where('id', 7) let promise = qb.where('id', 7)
.update('create_test', { .update('create_test', {
id: 7, id: 7,
@ -78,7 +78,7 @@ module.exports = function promiseTestRunner (qb) {
return expect(promise).to.be.fulfilled; return expect(promise).to.be.fulfilled;
}); });
test('Promise - Test set Array Update', () => { it('Promise - Test set Array Update', () => {
let object = { let object = {
id: 22, id: 22,
key: 'gogle', key: 'gogle',
@ -91,7 +91,7 @@ module.exports = function promiseTestRunner (qb) {
return expect(promise).to.be.fulfilled; return expect(promise).to.be.fulfilled;
}); });
test('Promise - Test where set update', () => { it('Promise - Test where set update', () => {
let promise = qb.where('id', 36) let promise = qb.where('id', 36)
.set('id', 36) .set('id', 36)
.set('key', 'gogle') .set('key', 'gogle')
@ -100,17 +100,17 @@ module.exports = function promiseTestRunner (qb) {
return expect(promise).to.be.fulfilled; return expect(promise).to.be.fulfilled;
}); });
test('Promise - Test delete', () => { it('Promise - Test delete', () => {
let promise = qb.delete('create_test', {id: 5}); let promise = qb.delete('create_test', {id: 5});
return expect(promise).to.be.fulfilled; return expect(promise).to.be.fulfilled;
}); });
test('Promise - Delete with where', () => { it('Promise - Delete with where', () => {
let promise = qb.where('id', 5) let promise = qb.where('id', 5)
.delete('create_test'); .delete('create_test');
return expect(promise).to.be.fulfilled; return expect(promise).to.be.fulfilled;
}); });
test('Promise - Delete multiple where values', () => { it('Promise - Delete multiple where values', () => {
let promise = qb.delete('create_test', { let promise = qb.delete('create_test', {
id: 5, id: 5,
key: 'gogle' key: 'gogle'
@ -119,8 +119,8 @@ module.exports = function promiseTestRunner (qb) {
return expect(promise).to.be.fulfilled; return expect(promise).to.be.fulfilled;
}); });
}); });
suite('Grouping tests -', () => { describe('Grouping tests -', () => {
test('Promise - Using grouping method', () => { it('Promise - Using grouping method', () => {
let promise = qb.select('id, key as k, val') let promise = qb.select('id, key as k, val')
.from('create_test') .from('create_test')
.groupStart() .groupStart()
@ -132,7 +132,7 @@ module.exports = function promiseTestRunner (qb) {
return expect(promise).to.be.fulfilled; return expect(promise).to.be.fulfilled;
}); });
test('Promise - Using where first grouping', () => { it('Promise - Using where first grouping', () => {
let promise = qb.select('id, key as k, val') let promise = qb.select('id, key as k, val')
.from('create_test') .from('create_test')
.where('id !=', 5) .where('id !=', 5)
@ -145,7 +145,7 @@ module.exports = function promiseTestRunner (qb) {
return expect(promise).to.be.fulfilled; return expect(promise).to.be.fulfilled;
}); });
test('Promise - Using or grouping method', () => { it('Promise - Using or grouping method', () => {
let promise = qb.select('id, key as k, val') let promise = qb.select('id, key as k, val')
.from('create_test') .from('create_test')
.groupStart() .groupStart()
@ -160,7 +160,7 @@ module.exports = function promiseTestRunner (qb) {
return expect(promise).to.be.fulfilled; return expect(promise).to.be.fulfilled;
}); });
test('Promise - Using or not grouping method', () => { it('Promise - Using or not grouping method', () => {
let promise = qb.select('id, key as k, val') let promise = qb.select('id, key as k, val')
.from('create_test') .from('create_test')
.groupStart() .groupStart()

View File

@ -7,19 +7,19 @@ const glob = require('glob');
const nodeQuery = reload('../lib/NodeQuery')(); const nodeQuery = reload('../lib/NodeQuery')();
const Adapter = reload('../lib/Adapter'); const Adapter = reload('../lib/Adapter');
suite('Base tests -', () => { describe('Base tests -', () => {
suite('Sanity check', () => { describe('Sanity check', () => {
let files = glob.sync(`${__dirname}/../lib/**/*.js`); let files = glob.sync(`${__dirname}/../lib/**/*.js`);
files.forEach(mod => { files.forEach(mod => {
let obj = require(mod); let obj = require(mod);
let shortName = mod.replace(/^\/(.*?)\/lib\/(.*?)\.js$/g, '$2'); let shortName = mod.replace(/^\/(.*?)\/lib\/(.*?)\.js$/g, '$2');
test(`${shortName} module is sane`, () => { it(`${shortName} module is sane`, () => {
expect(obj).to.be.ok; expect(obj).to.be.ok;
}); });
}); });
}); });
test('NodeQuery.getQuery with no instance', () => { it('NodeQuery.getQuery with no instance', () => {
// Hack for testing to work around node // Hack for testing to work around node
// module caching // module caching
let nodeQueryCopy = Object.create(nodeQuery); let nodeQueryCopy = Object.create(nodeQuery);
@ -29,7 +29,7 @@ suite('Base tests -', () => {
}).to.throw(Error, 'No Query Builder instance to return'); }).to.throw(Error, 'No Query Builder instance to return');
}); });
test('Invalid driver type', () => { it('Invalid driver type', () => {
expect(() => { expect(() => {
reload('../lib/NodeQuery')({ reload('../lib/NodeQuery')({
driver: 'Foo' driver: 'Foo'
@ -37,14 +37,14 @@ suite('Base tests -', () => {
}).to.throw(Error, 'Selected driver (Foo) does not exist!'); }).to.throw(Error, 'Selected driver (Foo) does not exist!');
}); });
test('Invalid adapter', () => { it('Invalid adapter', () => {
expect(() => { expect(() => {
let a = new Adapter(); let a = new Adapter();
a.execute(); a.execute();
}).to.throw(Error, 'Correct adapter not defined for query execution'); }).to.throw(Error, 'Correct adapter not defined for query execution');
}); });
test('Invalid adapter - missing transformResult', () => { it('Invalid adapter - missing transformResult', () => {
expect(() => { expect(() => {
let a = new Adapter(); let a = new Adapter();
a.transformResult([]); a.transformResult([]);

View File

@ -9,8 +9,8 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
set -xe set -xe
# Install sqlite3 # Install sqlite3
apt-get update -yqq echo -e 'http://dl-cdn.alpinelinux.org/alpine/edge/main\nhttp://dl-cdn.alpinelinux.org/alpine/edge/community\nhttp://dl-cdn.alpinelinux.org/alpine/edge/testing' > /etc/apk/repositories
apt-get install sqlite3 libsqlite3-dev -yqq apk add --no-cache git yarn sqlite3 libsqlite3
# Replace test config with docker config file # Replace test config with docker config file
mv "$DIR/config-ci.json" "$DIR/config.json" mv "$DIR/config-ci.json" "$DIR/config.json"

View File

@ -7,23 +7,23 @@ const expect = chai.expect;
let helpers = require('../lib/helpers'); let helpers = require('../lib/helpers');
suite('Helper Module Tests -', () => { describe('Helper Module Tests -', () => {
suite('Type-checking methods -', () => { describe('Type-checking methods -', () => {
suite('Object wrappers are listed as their native type', () => { describe('Object wrappers are listed as their native type', () => {
test('Boolean Wrapper returns \'boolean\' not \'object\'', () => { it('Boolean Wrapper returns \'boolean\' not \'object\'', () => {
let item = Boolean(true); let item = Boolean(true);
expect(helpers.type(item)).to.deep.equal('boolean'); expect(helpers.type(item)).to.deep.equal('boolean');
}); });
test('Number Wrapper returns \'number\' not \'object\'', () => { it('Number Wrapper returns \'number\' not \'object\'', () => {
let item = Number(4867); let item = Number(4867);
expect(helpers.type(item)).to.deep.equal('number'); expect(helpers.type(item)).to.deep.equal('number');
}); });
test('String Wrapper returns \'string\' not \'object\'', () => { it('String Wrapper returns \'string\' not \'object\'', () => {
let item = String('Foo'); let item = String('Foo');
expect(helpers.type(item)).to.deep.equal('string'); expect(helpers.type(item)).to.deep.equal('string');
}); });
}); });
suite('is..Method methods exist -', () => { describe('is..Method methods exist -', () => {
let types = [ let types = [
'Null', 'Null',
'Undefined', 'Undefined',
@ -39,19 +39,19 @@ suite('Helper Module Tests -', () => {
]; ];
types.forEach(type => { types.forEach(type => {
test(`is${type} method exists`, () => { it(`is${type} method exists`, () => {
assert.ok(helpers[`is${type}`]); assert.ok(helpers[`is${type}`]);
}); });
}); });
}); });
suite('isScalar -', () => { describe('isScalar -', () => {
let trueCases = { let trueCases = {
'Strings are scalar': 'foo', 'Strings are scalar': 'foo',
'Booleans are scalar': true, 'Booleans are scalar': true,
'Numbers are scalar': 545 'Numbers are scalar': 545
}; };
Object.keys(trueCases).forEach(desc => { Object.keys(trueCases).forEach(desc => {
test(desc, () => { it(desc, () => {
expect(helpers.isScalar(trueCases[desc])).to.be.true; expect(helpers.isScalar(trueCases[desc])).to.be.true;
}); });
}); });
@ -61,38 +61,38 @@ suite('Helper Module Tests -', () => {
'Objects are not scalar': [] 'Objects are not scalar': []
}; };
Object.keys(falseCases).forEach(desc => { Object.keys(falseCases).forEach(desc => {
test(desc, () => { it(desc, () => {
expect(helpers.isScalar(falseCases[desc])).to.be.false; expect(helpers.isScalar(falseCases[desc])).to.be.false;
}); });
}); });
}); });
suite('isInfinity -', () => { describe('isInfinity -', () => {
test('The type of 1/0 is infinity', () => { it('The type of 1/0 is infinity', () => {
expect(helpers.type(1 / 0)).to.equal('infinity'); expect(helpers.type(1 / 0)).to.equal('infinity');
}); });
test('isInfinity is the same as isInfinite', () => { it('isInfinity is the same as isInfinite', () => {
expect(helpers.isInfinite(1 / 0)).to.be.true; expect(helpers.isInfinite(1 / 0)).to.be.true;
}); });
}); });
suite('isNaN -', () => { describe('isNaN -', () => {
test('The type of 0 / 0 is NaN', () => { it('The type of 0 / 0 is NaN', () => {
expect(helpers.type(0 / 0)).to.equal('nan'); expect(helpers.type(0 / 0)).to.equal('nan');
}); });
test('isNaN method agrees with type', () => { it('isNaN method agrees with type', () => {
expect(helpers.isNaN(0 / 0)).to.be.true; expect(helpers.isNaN(0 / 0)).to.be.true;
}); });
}); });
}); });
suite('Other helper methods -', () => { describe('Other helper methods -', () => {
suite('stringTrim -', () => { describe('stringTrim -', () => {
test('stringTrim method works as expected', () => { it('stringTrim method works as expected', () => {
let orig = [' x y ', 'z ', ' q']; let orig = [' x y ', 'z ', ' q'];
let ret = ['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)).to.be.deep.equal(ret);
}); });
}); });
suite('arrayPluck -', () => { describe('arrayPluck -', () => {
let orig = [ let orig = [
{ {
foo: 1 foo: 1
@ -105,17 +105,17 @@ suite('Helper Module Tests -', () => {
} }
]; ];
test('Finding members in all objects', () => { it('Finding members in all objects', () => {
expect(helpers.arrayPluck(orig, 'foo')).to.be.deep.equal([1, 2, 3]); expect(helpers.arrayPluck(orig, 'foo')).to.be.deep.equal([1, 2, 3]);
}); });
test('Some members are missing in some objects', () => { it('Some members are missing in some objects', () => {
expect(helpers.arrayPluck(orig, 'bar')).to.be.deep.equal([10, 15]); expect(helpers.arrayPluck(orig, 'bar')).to.be.deep.equal([10, 15]);
}); });
test('Empty case', () => { it('Empty case', () => {
expect(helpers.arrayPluck([], 'apple')).to.be.deep.equal([]); expect(helpers.arrayPluck([], 'apple')).to.be.deep.equal([]);
}); });
}); });
suite('regexInArray -', () => { describe('regexInArray -', () => {
let orig = ['apple', ' string ', 6, 4, 7]; let orig = ['apple', ' string ', 6, 4, 7];
let cases = [ let cases = [
@ -131,7 +131,7 @@ suite('Helper Module Tests -', () => {
[0, 1].forEach(i => { [0, 1].forEach(i => {
let boolCase = cases[i]; let boolCase = cases[i];
Object.keys(boolCase).forEach(desc => { Object.keys(boolCase).forEach(desc => {
test(desc, () => { it(desc, () => {
if (i) { if (i) {
expect(helpers.regexInArray(orig, boolCase[desc])).to.be.true; expect(helpers.regexInArray(orig, boolCase[desc])).to.be.true;
} else { } else {
@ -141,15 +141,15 @@ suite('Helper Module Tests -', () => {
}); });
}); });
test('First argument is not an array', () => { it('First argument is not an array', () => {
expect(helpers.regexInArray(5, /5/)).to.be.false; expect(helpers.regexInArray(5, /5/)).to.be.false;
}); });
test('Array is empty', () => { it('Array is empty', () => {
expect(helpers.regexInArray([], /.*/)).to.be.false; expect(helpers.regexInArray([], /.*/)).to.be.false;
}); });
}); });
suite('upperCaseFirst -', () => { describe('upperCaseFirst -', () => {
test('Capitalizes only the first letter of the string', () => { 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')).to.equal('FOOBAR'); expect(helpers.upperCaseFirst('FOOBAR')).to.equal('FOOBAR');
}); });

View File

@ -1,9 +1,8 @@
--ui tdd
--bail --bail
--recursive --recursive
--reporter nyan --reporter nyan
--slow 200 --slow 200
--timeout 25000 --timeout 25000
--check-leaks --check-leaks
--growl --growl
test/**/*_test.js test/**/*_test.js

View File

@ -52,34 +52,34 @@ let whereMock = function (key, val) {
// ! Start Tests // ! Start Tests
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
suite('Query Parser Tests', () => { describe('Query Parser Tests', () => {
suite('Has operator tests', () => { describe('Has operator tests', () => {
test('Has operator', () => { it('Has operator', () => {
let matches = parser.hasOperator('foo <> 2'); let matches = parser.hasOperator('foo <> 2');
expect(matches).to.be.deep.equal(['<>']); expect(matches).to.be.deep.equal(['<>']);
}); });
test('Has no operator', () => { it('Has no operator', () => {
let matches = parser.hasOperator('foo'); let matches = parser.hasOperator('foo');
expect(matches).to.be.null; expect(matches).to.be.null;
}); });
}); });
suite('Where parser tests', () => { describe('Where parser tests', () => {
setup(() => { beforeAll(() => {
state = new State(); state = new State();
}); });
test('Has function full string', () => { it('Has function full string', () => {
whereMock('time < SUM(FOO(BAR()))'); whereMock('time < SUM(FOO(BAR()))');
parser.parseWhere(driver, state); parser.parseWhere(driver, state);
expect(state.whereMap) expect(state.whereMap)
.to.be.deep.equal(['"time" < SUM(FOO(BAR()))']); .to.be.deep.equal(['"time" < SUM(FOO(BAR()))']);
}); });
test('Has function key/val', () => { it('Has function key/val', () => {
whereMock('time <', 'SUM(FOO(BAR()))'); whereMock('time <', 'SUM(FOO(BAR()))');
parser.parseWhere(driver, state); parser.parseWhere(driver, state);
expect(state.whereMap) expect(state.whereMap)
.to.be.deep.equal(['"time" < SUM(FOO(BAR()))']); .to.be.deep.equal(['"time" < SUM(FOO(BAR()))']);
}); });
test('Has function key/val object', () => { it('Has function key/val object', () => {
whereMock({ whereMock({
'time <': 'SUM(FOO(BAR(\'x\')))' 'time <': 'SUM(FOO(BAR(\'x\')))'
}); });
@ -87,7 +87,7 @@ suite('Query Parser Tests', () => {
expect(state.whereMap) expect(state.whereMap)
.to.be.deep.equal(['"time" < SUM(FOO(BAR(\'x\')))']); .to.be.deep.equal(['"time" < SUM(FOO(BAR(\'x\')))']);
}); });
test('Has literal value', () => { it('Has literal value', () => {
whereMock({ whereMock({
foo: 3 foo: 3
}); });
@ -97,7 +97,7 @@ suite('Query Parser Tests', () => {
expect(state.whereValues) expect(state.whereValues)
.to.be.deep.equal(['3']); .to.be.deep.equal(['3']);
}); });
test('Has multiple literal values', () => { it('Has multiple literal values', () => {
whereMock({ whereMock({
foo: 3, foo: 3,
bar: 5 bar: 5
@ -109,7 +109,7 @@ suite('Query Parser Tests', () => {
.to.be.deep.equal(['3', '5']); .to.be.deep.equal(['3', '5']);
}); });
}); });
suite('Parse join tests', () => { describe('Parse join tests', () => {
let data = [ let data = [
{ {
desc: 'Simple equals condition', desc: 'Simple equals condition',
@ -131,13 +131,13 @@ suite('Query Parser Tests', () => {
]; ];
data.forEach(datum => { data.forEach(datum => {
test(datum.desc, () => { it(datum.desc, () => {
let matches = parser.parseJoin(datum.join); let matches = parser.parseJoin(datum.join);
expect(matches.combined).to.be.deep.equal(datum.expected); expect(matches.combined).to.be.deep.equal(datum.expected);
}); });
}); });
}); });
suite('Compile join tests', () => { describe('Compile join tests', () => {
let data = [ let data = [
{ {
desc: 'Simple equals condition', desc: 'Simple equals condition',
@ -159,7 +159,7 @@ suite('Query Parser Tests', () => {
]; ];
data.forEach(datum => { data.forEach(datum => {
test(datum.desc, () => { it(datum.desc, () => {
let join = parser.compileJoin(datum.clause); let join = parser.compileJoin(datum.clause);
expect(join).to.be.deep.equal(datum.expected); expect(join).to.be.deep.equal(datum.expected);
}); });