mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-19 00:15:43 +01:00
fix tests
This commit is contained in:
parent
0bd0924aee
commit
9f459e600c
@ -8,11 +8,8 @@ before_script:
|
||||
- psql -c 'create database unleash_test;' -U postgres
|
||||
script:
|
||||
- npm install
|
||||
- npm run test:ci
|
||||
- npm run test
|
||||
notifications:
|
||||
hipchat:
|
||||
rooms:
|
||||
secure: GiIDk52xccnUKnevjLE+w6eUXg0jfV7oOmagw5VnOV5jXGUxdzMk/Q9um+oSClEPE51IvF76zoFEKPIX/CNdjgalEr+CZADy1gene/YRGrNgrXmYYmiU1/dNzelpla1WpKPrY2pkbOgKxrCR9ScID+pMs6vzvJnPwK9vu66W61U=
|
||||
slack:
|
||||
secure: MroremSKwtQkwPbrXjgs9hIqKTCDKk7bAIXXzjcS6wXC9uRaFgwFaW8oO3vBxtWa4BL44EQBLE/rboWgqFER62+XgXNgEqGZqrcJHJvby4r+dUNMPI64OZvWdIiydIYxLo8C1C4x5PqBup0xuLq8h/SBnNvA2NLgkjuvzOi+v/Q=
|
||||
addons:
|
||||
|
19
README.md
19
README.md
@ -3,9 +3,9 @@
|
||||
__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) __
|
||||
|
||||
[](https://travis-ci.org/Unleash/unleash)
|
||||
[](https://coveralls.io/github/Unleash/unleash?branch=master)
|
||||
[](https://david-dm.org/Unleash/unleash?path=packages/unleash-api)
|
||||
[](https://david-dm.org/Unleash/unleash?path=packages/unleash-api#info=devD)
|
||||
[](https://coveralls.io/github/Unleash/unleash?branch=master)
|
||||
[](https://david-dm.org/Unleash/unleash?path=packages/unleash-api)
|
||||
[](https://david-dm.org/Unleash/unleash?path=packages/unleash-api#info=devD)
|
||||

|
||||
[Demo](http://unleash.herokuapp.com/) instance on Heroku
|
||||
|
||||
@ -55,18 +55,19 @@ export TEST_DATABASE_URL=postgres://unleash_user:passord@localhost:5432/unleash_
|
||||
// Install dependencies
|
||||
npm install
|
||||
|
||||
// Run migrations in your local DBs (via unleash-api)
|
||||
npm run db-migrate
|
||||
DATABASE_URL=$TEST_DATABASE_URL npm run db-migrate
|
||||
// Build unleash-frontend
|
||||
// (yes this is a bit wierd and be easier when we have a release of the frontend artifact).
|
||||
// You can of course "npm link unleash-frontend" instead
|
||||
cd node_modules/unleash-frontend && npm install
|
||||
|
||||
// Start server
|
||||
npm start
|
||||
// Start server in development
|
||||
npm start:dev
|
||||
|
||||
// Admin dashboard
|
||||
http://localhost:4242
|
||||
|
||||
// Feature API:
|
||||
http://localhost:4242/features
|
||||
http://localhost:4242/api/features
|
||||
|
||||
// Execute tests in all packages:
|
||||
npm test
|
||||
|
@ -4,7 +4,7 @@
|
||||
process.env.NODE_ENV = 'production';
|
||||
|
||||
const program = require('commander');
|
||||
const unleash = require('../server.js');
|
||||
const unleash = require('../server-prod.js');
|
||||
|
||||
|
||||
program
|
||||
|
@ -14,8 +14,7 @@ class ClientMetricsStore {
|
||||
|
||||
constructor (db) {
|
||||
this.db = db;
|
||||
this._removeMetricsOlderThanOneHour();
|
||||
|
||||
setTimeout(() => this._removeMetricsOlderThanOneHour(), 10).unref();
|
||||
setInterval(() => this._removeMetricsOlderThanOneHour(), 60 * 60 * 1000).unref();
|
||||
}
|
||||
|
||||
|
17
migrator.js
17
migrator.js
@ -3,23 +3,14 @@
|
||||
const DBMigrate = require('db-migrate');
|
||||
const path = require('path');
|
||||
|
||||
function findUnleashApiRoot () {
|
||||
try {
|
||||
return path.dirname(require.resolve('unleash-api/package.json'));
|
||||
} catch (e) {}
|
||||
try {
|
||||
return path.dirname(require.resolve('../unleash-api/package.json'));
|
||||
} catch (e) {}
|
||||
return process.cwd();
|
||||
}
|
||||
|
||||
function migrateDb (dbUri) {
|
||||
console.log(dbUri);
|
||||
const dbmigrate = DBMigrate.getInstance(true, {
|
||||
cwd: findUnleashApiRoot(),
|
||||
config: { custom: dbUri },
|
||||
cwd: __dirname,
|
||||
config: { "custom": dbUri},
|
||||
env: 'custom' }
|
||||
);
|
||||
return dbmigrate.up();
|
||||
}
|
||||
|
||||
module.exports = migrateDb;
|
||||
module.exports = migrateDb;
|
13
package.json
13
package.json
@ -33,16 +33,14 @@
|
||||
"unleash": "./bin/unleash.js"
|
||||
},
|
||||
"scripts": {
|
||||
"db-migrate-and-start": "npm run db-migrate && npm run start",
|
||||
"start": "node dev-server.js",
|
||||
"start:dev": "NODE_ENV=development supervisor --ignore ./node_modules/ dev-server.js",
|
||||
"start": "node server-dev.js",
|
||||
"start:dev": "NODE_ENV=development supervisor --ignore ./node_modules/ server-dev.js",
|
||||
"start:dev:pg": "pg_virtualenv npm run start:dev:pg-chain",
|
||||
"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 && npm run test:coverage",
|
||||
"test:unit": "mocha test/unit/**/*.js ",
|
||||
"test:ci": "npm run db-migrate && npm run test",
|
||||
"test:docker": "./scripts/docker-postgres.sh",
|
||||
"test:watch": "mocha --watch test test/*",
|
||||
"test:pg-virtualenv": "pg_virtualenv npm run test:pg-virtualenv-chai",
|
||||
@ -52,10 +50,10 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"body-parser": "1.15.2",
|
||||
"cookie-parser": "^1.4.1",
|
||||
"commander": "^2.9.0",
|
||||
"db-migrate": "0.10.0-beta.17",
|
||||
"db-migrate-pg": "0.1.10",
|
||||
"cookie-parser": "^1.4.1",
|
||||
"db-migrate": "0.10.0-beta.20",
|
||||
"db-migrate-pg": "0.1.11",
|
||||
"deep-diff": "^0.3.3",
|
||||
"errorhandler": "^1.4.3",
|
||||
"express": "4.14.0",
|
||||
@ -67,6 +65,7 @@
|
||||
"moment": "^2.15.2",
|
||||
"pg": "^6.1.0",
|
||||
"serve-favicon": "^2.3.0",
|
||||
"unleash-frontend": "github:unleash/unleash-frontend",
|
||||
"yallist": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -1,8 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
const request = require('./test-helper').request;
|
||||
const specHelper = require('./util/test-helper');
|
||||
let request;
|
||||
|
||||
describe('The event api', () => {
|
||||
beforeEach(done => {
|
||||
specHelper.setupApp().then((app) => {
|
||||
request = app.request;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('returns events', done => {
|
||||
request
|
||||
.get('/api/events')
|
||||
|
@ -2,17 +2,19 @@
|
||||
|
||||
const logger = require('../../lib/logger');
|
||||
const assert = require('assert');
|
||||
const specHelper = require('./test-helper');
|
||||
const request = specHelper.request;
|
||||
const specHelper = require('./util/test-helper');
|
||||
const stringify = function (o) {
|
||||
return JSON.stringify(o, null, ' ');
|
||||
};
|
||||
|
||||
let request;
|
||||
|
||||
describe('The features api', () => {
|
||||
beforeEach(done => {
|
||||
specHelper.db.resetAndSetup()
|
||||
.then(done.bind(null, null))
|
||||
.catch(done);
|
||||
specHelper.setupApp().then((app) => {
|
||||
request = app.request;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('returns three feature toggles', done => {
|
||||
|
@ -1,18 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const specHelper = require('./test-helper');
|
||||
const request = specHelper.request;
|
||||
const specHelper = require('./util/test-helper');
|
||||
const stringify = function (o) {
|
||||
return JSON.stringify(o, null, ' ');
|
||||
};
|
||||
|
||||
let request;
|
||||
|
||||
describe('The archive features api', () => {
|
||||
beforeEach(done => {
|
||||
specHelper.db.resetAndSetup()
|
||||
.then(done.bind(null, null))
|
||||
.catch(done);
|
||||
});
|
||||
specHelper.setupApp().then((app) => {
|
||||
request = app.request;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('returns three archived toggles', done => {
|
||||
request
|
||||
|
@ -1,9 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
const specHelper = require('./test-helper');
|
||||
const request = specHelper.request;
|
||||
const specHelper = require('./util/test-helper');
|
||||
|
||||
let request;
|
||||
|
||||
describe('The routes', () => {
|
||||
beforeEach(done => {
|
||||
specHelper.setupApp().then((app) => {
|
||||
request = app.request;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('healthcheck', () => {
|
||||
it('returns health good', done => {
|
||||
request.get('/health')
|
||||
|
@ -1,13 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const specHelper = require('./test-helper');
|
||||
const request = specHelper.request;
|
||||
const specHelper = require('./util/test-helper');
|
||||
let request;
|
||||
|
||||
describe('The strategy api', () => {
|
||||
beforeEach(done => {
|
||||
specHelper.db.resetAndSetup()
|
||||
.then(done.bind(null, null))
|
||||
.catch(done);
|
||||
specHelper.setupApp().then((app) => {
|
||||
request = app.request;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('gets all strategies', done => {
|
||||
|
@ -2,30 +2,25 @@
|
||||
|
||||
process.env.NODE_ENV = 'test';
|
||||
|
||||
// Mute migrator
|
||||
require('db-migrate-shared').log.silence(true);
|
||||
|
||||
const BPromise = require('bluebird');
|
||||
let request = require('supertest');
|
||||
const migrator = require('../../migrator');
|
||||
let supertest = require('supertest');
|
||||
|
||||
const options = {
|
||||
databaseUri: require('./database-config').getDatabaseUri(),
|
||||
};
|
||||
|
||||
const { createStores } = require('../../lib/db');
|
||||
const migrator = require('../../../migrator');
|
||||
const { createStores } = require('../../../lib/db');
|
||||
|
||||
const stores = createStores(options);
|
||||
process.env.DATABASE_URL = options.databaseUri
|
||||
|
||||
const app = require('../../app')({
|
||||
baseUriPath: '',
|
||||
stores,
|
||||
const createApp = migrator(options.databaseUri).then(() => {
|
||||
const stores = createStores(options);
|
||||
const app = require('../../../app')({stores});
|
||||
return { stores, request: supertest(app) };
|
||||
});
|
||||
|
||||
BPromise.promisifyAll(request);
|
||||
request = request(app);
|
||||
|
||||
function createStrategies () {
|
||||
function createStrategies (stores) {
|
||||
return BPromise.map([
|
||||
{
|
||||
name: 'default',
|
||||
@ -42,7 +37,7 @@ function createStrategies () {
|
||||
], strategy => stores.strategyStore._createStrategy(strategy));
|
||||
}
|
||||
|
||||
function createFeatures () {
|
||||
function createFeatures (stores) {
|
||||
return BPromise.map([
|
||||
{
|
||||
name: 'featureX',
|
||||
@ -106,29 +101,28 @@ function createFeatures () {
|
||||
], feature => stores.featureToggleStore._createFeature(feature));
|
||||
}
|
||||
|
||||
function destroyStrategies () {
|
||||
function destroyStrategies (stores) {
|
||||
return stores.db('strategies').del();
|
||||
}
|
||||
|
||||
function destroyFeatures () {
|
||||
function destroyFeatures (stores) {
|
||||
return stores.db('features').del();
|
||||
}
|
||||
|
||||
function resetDatabase () {
|
||||
return BPromise.all([destroyStrategies(), destroyFeatures()]);
|
||||
function resetDatabase (stores) {
|
||||
return BPromise.all([destroyStrategies(stores), destroyFeatures(stores)]);
|
||||
}
|
||||
|
||||
function setupDatabase () {
|
||||
return BPromise.all([migrator(options.databaseUri), createStrategies(), createFeatures()]);
|
||||
function setupDatabase (stores) {
|
||||
return BPromise.all([createStrategies(stores), createFeatures(stores)]);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
request,
|
||||
db: {
|
||||
reset: resetDatabase,
|
||||
setup: setupDatabase,
|
||||
resetAndSetup () {
|
||||
return resetDatabase().then(setupDatabase);
|
||||
},
|
||||
},
|
||||
setupApp () {
|
||||
return createApp.then((app) => {
|
||||
return resetDatabase(app.stores)
|
||||
.then(() => setupDatabase(app.stores))
|
||||
.then(() => app);
|
||||
});
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user