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",
"globstar": "^1.0.0",
"happiness": "^7.1.2",
"istanbul": "~0.4.2",
"mocha": "^3.0.0",
"jest": "^19.0.2",
"npm-run-all": "^3.0.0",
"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": "istanbul cover ./node_modules/mocha/bin/_mocha",
"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\"",
"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": "npm-run-all lint:tests lint:src happy",
"lint:src": "eslint ./lib",
"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 qb = nodeQuery.getQuery();
suite('Dblite adapter tests -', () => {
suiteSetup(done => {
describe('Dblite adapter tests -', () => {
beforeAll(done => {
// Set up the sqlite database
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);';
@ -29,7 +29,7 @@ suite('Dblite adapter tests -', () => {
});
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')
.from('create_test')
.where('id', 'ABS(-88)')
@ -37,7 +37,7 @@ suite('Dblite adapter tests -', () => {
expect(promise).to.be.fulfilled;
});
test('Promise - Test Insert Batch', () => {
it('Promise - Test Insert Batch', () => {
let data = [
{
id: 544,
@ -57,7 +57,7 @@ suite('Dblite adapter tests -', () => {
let promise = qb.insertBatch('create_test', data);
expect(promise).to.be.fulfilled;
});
suiteTeardown(() => {
afterAll(() => {
qb.end();
});
});

View File

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

View File

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

View File

@ -18,21 +18,21 @@ let nodeQuery = reload('../../lib/NodeQuery')(config);
let qb = nodeQuery.getQuery();
let qb2 = null;
suite('Pg adapter tests -', () => {
test('nodeQuery.getQuery = nodeQuery.init', () => {
describe('Pg adapter tests -', () => {
it('nodeQuery.getQuery = nodeQuery.init', () => {
expect(nodeQuery.getQuery())
.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 nodeQuery = reload('../../lib/NodeQuery')(config);
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 {
reload('../../lib/NodeQuery')({});
done(true);
@ -44,7 +44,7 @@ suite('Pg adapter tests -', () => {
});
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')
.from('create_test')
.where('id', 'CEILING(SQRT(88))')
@ -52,11 +52,11 @@ suite('Pg adapter tests -', () => {
return expect(promise).to.be.fulfilled;
});
test('Promise - Test Truncate', () => {
it('Promise - Test Truncate', () => {
let promise = qb.truncate('create_test');
return expect(promise).to.be.fulfilled;
});
test('Promise - Test Insert Batch', () => {
it('Promise - Test Insert Batch', () => {
let data = [
{
id: 544,
@ -76,7 +76,7 @@ suite('Pg adapter tests -', () => {
let promise = qb.insertBatch('create_test', data);
return expect(promise).to.be.fulfilled;
});
suiteTeardown(() => {
afterAll(() => {
qb.end();
qb2.end();
});

View File

@ -15,8 +15,8 @@ const config = testBase.config;
let nodeQuery = require('../../lib/NodeQuery')(config.sqlite3);
let qb = nodeQuery.getQuery();
suite('Sqlite3 adapter tests -', () => {
suiteSetup(done => {
describe('Sqlite3 adapter tests -', () => {
beforeAll(done => {
// Set up the sqlite database
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);';
@ -29,7 +29,7 @@ suite('Sqlite3 adapter tests -', () => {
});
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')
.from('create_test')
.where('id', 'ABS(-88)')
@ -37,7 +37,7 @@ suite('Sqlite3 adapter tests -', () => {
expect(promise).to.be.fulfilled;
});
test('Promise - Test Insert Batch', () => {
it('Promise - Test Insert Batch', () => {
let data = [
{
id: 544,
@ -57,7 +57,7 @@ suite('Sqlite3 adapter tests -', () => {
let promise = qb.insertBatch('create_test', data);
expect(promise).to.be.fulfilled;
});
suiteTeardown(() => {
afterAll(() => {
qb.end();
});
});

View File

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

View File

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

View File

@ -9,8 +9,8 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
set -xe
# Install sqlite3
apt-get update -yqq
apt-get install sqlite3 libsqlite3-dev -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
apk add --no-cache git yarn sqlite3 libsqlite3
# Replace test config with docker config file
mv "$DIR/config-ci.json" "$DIR/config.json"

View File

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

View File

@ -1,4 +1,3 @@
--ui tdd
--bail
--recursive
--reporter nyan

View File

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