Skip to content

Commit

Permalink
Moved to jest
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmosgenius committed Feb 17, 2017
1 parent 063e3b5 commit 62ebcf3
Show file tree
Hide file tree
Showing 16 changed files with 1,221 additions and 425 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"root": true,
"parserOptions": {
"ecmaVersion": 6,
"ecmaVersion": 8,
"ecmaFeatures": {
"impliedStrict": true
}
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
webhooked
- Run Deamon based on config file
- Rest api support
- Store config in leveldb
- Auth support

Webhooked
=========

Expand Down
36 changes: 0 additions & 36 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,14 @@
const gulp = require('gulp');
const del = require('del');
const runSequence = require('run-sequence');
const chalk = require('chalk');
const colors = require('colors');
const mocha = require('gulp-mocha');
const nodemon = require('gulp-nodemon');
const istanbul = require('gulp-istanbul');

chalk.enabled = true;
colors.enabled = true;

const PORT = 9000;
const testdb = './testdb';

gulp.task('instrument', () => {
return gulp.src(['server/**/*.js'])
.pipe(istanbul())
.pipe(istanbul.hookRequire());
});

gulp.task('mocha', ['instrument'] ,() => {
return gulp.src(['test/**/*.js'])
.pipe(mocha({
bail: true,
require: ['should']
}))
.pipe(istanbul.writeReports());
// .pipe(istanbul.enforceThresholds({ thresholds: { global: 90 } }));
});

gulp.task('testenv', () => {
return process.env.DB_PATH = testdb;
});

gulp.task('deltestdb', () => {
del.sync(testdb);
});

gulp.task('watch', () => {
return nodemon({
script: 'index.js',
Expand All @@ -48,11 +20,3 @@ gulp.task('watch', () => {
});

gulp.task('default', ['watch']);
gulp.task('test', (done) => {
runSequence(
'testenv',
'mocha',
'deltestdb',
done
);
});
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';
require('dotenv').config();
require('./logging');

Expand Down
1 change: 0 additions & 1 deletion logging.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';
const co = require('co');
const uuid = require('uuid');
const chalk = require('chalk');
Expand Down
29 changes: 14 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
{
"name": "webhooked",
"version": "1.0.0",
"version": "0.0.1",
"description": "Webhooked",
"main": "index.js",
"scripts": {
"test": "gulp test",
"test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/**/*",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha --report text --report text-summary --report html -- --reporter spec --check-leaks test/**/*",
"test": "node --harmony-async-await ./node_modules/.bin/jest -i --forceExit",
"start": "node index.js",
"server": "gulp watch | bunyan -o short"
},
Expand All @@ -16,7 +14,8 @@
},
"keywords": [
"webhooked",
"deployment"
"deployment",
"webhook"
],
"author": "Sharat M R",
"license": "MIT",
Expand All @@ -27,32 +26,32 @@
"engines": {
"node": ">=7.0.0"
},
"jest": {
"verbose": true,
"testEnvironment": "node",
"collectCoverage": true
},
"devDependencies": {
"colors": "^1.1.2",
"del": "^2.2.2",
"eslint": "^3.13.0",
"gulp": "^3.9.1",
"gulp-istanbul": "^1.0.0",
"gulp-mocha": "^3.0.0",
"gulp-nodemon": "^2.1.0",
"istanbul": "^0.4.4",
"mocha": "^3.0.0",
"run-sequence": "^1.2.2",
"should": "^10.0.0"
"jest": "^18.1.0",
"should": "^11.2.0"
},
"dependencies": {
"bluebird": "^3.4.7",
"bunyan": "^1.8.5",
"chalk": "^1.1.3",
"co": "^4.6.0",
"dotenv": "^2.0.0",
"kcors": "^2.2.0",
"dotenv": "^4.0.0",
"kcors": "^2.2.1",
"koa": "^2.0.0",
"koa-bodyparser": "^3.2.0",
"koa-etag": "^3.0.0",
"koa-response-time": "^2.0.0",
"koa-router": "^7.1.0",
"level": "^1.5.0",
"level": "^1.6.0",
"through2": "^2.0.3"
}
}
2 changes: 0 additions & 2 deletions server/db/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const db = require('./store');
const Model = require('./model');
const Serializer = require('./serializer');
Expand Down
13 changes: 6 additions & 7 deletions server/db/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@ class Model {
static getKey (id) {
return `${this.getBase()}${id}`;
}
}

Model.findById = co.wrap(function* (id) {
let key = this.getKey(id);
let obj = yield db.get(key);

return this.fromObj(obj);
});
static async findById(id) {
const key = this.getKey(id);
const obj = await db.get(key);
return this.fromObj(obj);
}
}

Model.find = function() {
let stream = db.createReadStream()
Expand Down
2 changes: 0 additions & 2 deletions server/db/serializer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const co = require('co');
const ValidationError = require('./validation').ValidationError;

Expand Down
2 changes: 0 additions & 2 deletions server/db/validation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

class ValidationError extends Error {
constructor (msg, status=400) {
super();
Expand Down
2 changes: 0 additions & 2 deletions server/hook/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const co = require('co');
const KoaRouter = require('koa-router');
const Hook = require('./model');
Expand Down
2 changes: 0 additions & 2 deletions server/hook/model.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const db = require('../db');

class Hook extends db.Model{}
Expand Down
2 changes: 0 additions & 2 deletions server/hook/serializer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const co = require('co');

const db = require('../db');
Expand Down
1 change: 1 addition & 0 deletions test/unit/db/model_test.js → test/unit/db/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ const Model = require('../../../server/db/model');

describe('Model', () => {
class MockModel extends Model{}
it('test model');
});
10 changes: 4 additions & 6 deletions test/unit/db/store_test.js → test/unit/db/store.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
const should = require('should');
const store = require('../../../server/db/store');

const db = store.db;

describe('Store', () => {
it('put', (done) => {
store.put('testput', 123).then(()=>{
db.get('testput', (err, value) => {
value.should.eql(123);
expect(value).toEqual(123);
done(err);
});
});
Expand All @@ -17,7 +15,7 @@ describe('Store', () => {
db.put('testget', 1234, (err) => {
if(err) done(err);
store.get('testget').then((value)=>{
value.should.eql(1234);
expect(value).toEqual(1234);
done();
}).catch(done);
});
Expand All @@ -30,8 +28,8 @@ describe('Store', () => {
})
.then(()=> {
db.get('testdel', (err, value) => {
err.name.should.eql('NotFoundError');
should.not.exist(value);
expect(err.name).toEqual('NotFoundError');
expect(value).toBeUndefined();
done();
});
}).catch(done);
Expand Down
Loading

0 comments on commit 62ebcf3

Please sign in to comment.