Skip to content

Commit

Permalink
Merge pull request #168 from Unleash/ava
Browse files Browse the repository at this point in the history
Ava
  • Loading branch information
sveisvei committed Nov 13, 2016
2 parents 8ec9aa0 + cbf3db4 commit 41fc1d6
Show file tree
Hide file tree
Showing 30 changed files with 804 additions and 791 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ unleash-server.tar.gz
jsconfig.json
typings
.vscode
.nyc_output
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ before_script:
- psql -c 'create database unleash_test;' -U postgres
script:
- npm install
- npm run test
- npm run test:coverage
after_success:
- npm run test:coverage-report
notifications:
slack:
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# unleash

__Warning: We are in the process of splitting up unleash into multiple packages in this repository, if you want to test the previous package see [previous tag](https://github.com/finn-no/unleash/tree/v1.0.0-alpha.2) __
__Warning: We are in the process of splitting up unleash into multiple packages in this repository, if you want to test the previous package see [previous tag](https://github.com/unleash/unleash/tree/v1.0.0-alpha.2) __

[![Build Status](https://travis-ci.org/Unleash/unleash.svg?branch=master)](https://travis-ci.org/Unleash/unleash)
[![Coverage Status](https://coveralls.io/repos/github/Unleash/unleash/badge.svg?branch=master)](https://coveralls.io/github/Unleash/unleash?branch=master)
Expand All @@ -12,11 +12,11 @@ __Warning: We are in the process of splitting up unleash into multiple packages
This repo contains the unleash-server, which contains the admin UI and a place to ask for the status of features. In order to make use of unleash you will also need a client implementation.

Known client implementations:
- [unleash-client-java](https://github.com/finn-no/unleash-client-java)
- [unleash-client-node](https://github.com/finn-no/unleash-client-node)
- [unleash-client-java](https://github.com/unleash/unleash-client-java)
- [unleash-client-node](https://github.com/unleash/unleash-client-node)

## Project details
- [Project Roadmap](https://github.com/finn-no/unleash/wiki/Roadmap)
- [Project Roadmap](https://github.com/unleash/unleash/wiki/Roadmap)

## Run with docker
We have set up docker-compose to start postgres and the unleash server together. This makes it really fast to start up
Expand Down
3 changes: 2 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const log4js = require('log4js');
const logger = require('./lib/logger');
const routes = require('./lib/routes');
const path = require('path');
const errorHandler = require('errorhandler');

module.exports = function (config) {
const app = express();
Expand Down Expand Up @@ -47,7 +48,7 @@ module.exports = function (config) {
app.use(baseUriPath, router);

if (process.env.NODE_ENV !== 'production') {
app.use(require('errorhandler')());
app.use(errorHandler());
}

return app;
Expand Down
8 changes: 4 additions & 4 deletions lib/db/db-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

const knex = require('knex');

module.exports.createDb = function (databaseConnection, schema = 'public') {
module.exports.createDb = function ({ databaseUri, poolMin = 2, poolMax = 20, databaseSchema = 'public' }) {
const db = knex({
client: 'pg',
connection: databaseConnection,
pool: { min: 2, max: 20 },
searchPath: schema,
connection: databaseUri,
pool: { min: poolMin, max: poolMax },
searchPath: databaseSchema,
});

return db;
Expand Down
2 changes: 1 addition & 1 deletion lib/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const ClientMetricsStore = require('./client-metrics-store');
const ClientStrategyStore = require('./client-strategy-store');

module.exports.createStores = (config) => {
const db = createDb(config.databaseUri, config.databaseSchema);
const db = createDb(config);
const eventStore = new EventStore(db);

return {
Expand Down
13 changes: 6 additions & 7 deletions migrator.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
'use strict';

const DBMigrate = require('db-migrate');
const path = require('path');
const { getInstance } = require('db-migrate');
const parseDbUrl = require('parse-database-url');

function migrateDb (dbUrl, schema = "public") {
const custom = parseDbUrl(dbUrl);
custom.schema = schema;
const dbmigrate = DBMigrate.getInstance(true, {
function migrateDb ({ databaseUri, databaseSchema = 'public' }) {
const custom = parseDbUrl(databaseUri);
custom.schema = databaseSchema;
const dbmigrate = getInstance(true, {
cwd: __dirname,
config: { custom },
env: 'custom' }
);
return dbmigrate.up();
}

module.exports = migrateDb;
module.exports = migrateDb;
23 changes: 11 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
],
"repository": {
"type": "git",
"url": "ssh://git@github.com:finn-no/unleash.git"
"url": "ssh://git@github.com:unleash/unleash.git"
},
"bugs": {
"url": "https://github.com/finn-no/unleash/issues"
"url": "https://github.com/unleash/unleash/issues"
},
"engines": {
"node": "6"
Expand All @@ -39,14 +39,13 @@
"start:dev:pg-chain": "export DATABASE_URL=postgres://$PGUSER:$PGPASSWORD@localhost:$PGPORT/postgres ; db-migrate up && npm run start:dev",
"db-migrate": "db-migrate up",
"db-migrate:down": "db-migrate down",
"test": "export PORT=4243 ; mocha --recursive test",
"test:unit": "mocha test/unit/**/*.js ",
"test": "PORT=4243 ava **/**test.js",
"test:docker": "./scripts/docker-postgres.sh",
"test:watch": "mocha --watch test test/*",
"test:watch": "npm run test -- --watch",
"test:pg-virtualenv": "pg_virtualenv npm run test:pg-virtualenv-chai",
"test:pg-virtualenv-chain": "export TEST_DATABASE_URL=postgres://$PGUSER:$PGPASSWORD@localhost:$PGPORT/postgres ; npm run db-migrate-testdb && npm test",
"test:coverage": "istanbul cover ./node_modules/mocha/bin/_mocha test --report lcovonly -- -R spec --recursive",
"test:coverage-report": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
"test:coverage": "nyc npm run test",
"test:coverage-report": "nyc report --reporter=text-lcov | coveralls"
},
"dependencies": {
"body-parser": "1.15.2",
Expand All @@ -70,13 +69,13 @@
"yallist": "^2.0.0"
},
"devDependencies": {
"@types/node": "^6.0.46",
"ava": "^0.16.0",
"coveralls": "^2.11.14",
"istanbul": "^0.4.5",
"mocha": "^3.0.2",
"mocha-lcov-reporter": "1.2.0",
"coveralls": "^2.11.15",
"nyc": "^8.4.0",
"sinon": "^1.17.5",
"supertest": "^2.0.0",
"superagent": "^2.3.0",
"supertest": "^2.0.1",
"supervisor": "^0.11.0",
"unleash-frontend": "1.0.0-alpha.2"
}
Expand Down
3 changes: 2 additions & 1 deletion server-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const logger = require('./lib/logger');
const migrator = require('./migrator');
const { createStores } = require('./lib/db');
const getApp = require('./app');

const DEFAULT_OPTIONS = {
databaseUri: process.env.DATABASE_URL || 'postgres://unleash_user:passord@localhost:5432/unleash',
Expand All @@ -21,7 +22,7 @@ function createApp (options) {
stores,
};

const app = require('./app')(config);
const app = getApp(config);
const server = app.listen(app.get('port'), () => {
logger.info(`Unleash started on ${app.get('port')}`);
});
Expand Down
6 changes: 0 additions & 6 deletions test/.eslintrc

This file was deleted.

42 changes: 21 additions & 21 deletions test/e2e/event-api.test.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
'use strict';

const specHelper = require('./util/test-helper');
let request;
const test = require('ava');
const { setupApp } = require('./util/test-helper');
const logger = require('../../lib/logger');

describe('The event api', () => {
beforeEach(done => {
specHelper.setupApp().then((app) => {
request = app.request;
done();
});
});
test.beforeEach(() => {
logger.setLevel('FATAL');
});

it('returns events', done => {
request
.get('/api/events')
.expect('Content-Type', /json/)
.expect(200, done);
});
test.serial('returns events', async (t) => {
const { request, destroy } = await setupApp('event_api_serial');
return request
.get('/api/events')
.expect('Content-Type', /json/)
.expect(200)
.then(destroy);
});

it('returns events given a name', done => {
request
.get('/api/events/myname')
.expect('Content-Type', /json/)
.expect(200, done);
});
test.serial('returns events given a name', async (t) => {
const { request, destroy } = await setupApp('event_api_serial');
return request
.get('/api/events/myname')
.expect('Content-Type', /json/)
.expect(200)
.then(destroy);
});

0 comments on commit 41fc1d6

Please sign in to comment.