1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-01 00:08:27 +01:00

Merge pull request #223 from Unleash/pass-along-hooks

pass along hooks, add test to server impl
This commit is contained in:
Sveinung Røsaker 2017-06-06 13:36:06 +02:00 committed by GitHub
commit ef3bcc11a5
3 changed files with 56 additions and 7 deletions

View File

@ -3,6 +3,9 @@
"finn", "finn",
"finn/node" "finn/node"
], ],
"parserOptions": {
"ecmaVersion": "2017"
},
"rules": { "rules": {
"max-nested-callbacks": "off" "max-nested-callbacks": "off"
} }

View File

@ -15,15 +15,10 @@ function createApp (options) {
const stores = createStores(options); const stores = createStores(options);
const eventBus = new EventEmitter(); const eventBus = new EventEmitter();
const config = { const config = Object.assign({
baseUriPath: options.baseUriPath,
serverMetrics: options.serverMetrics,
enableRequestLogger: options.enableRequestLogger,
port: options.port,
publicFolder: options.publicFolder,
stores, stores,
eventBus, eventBus,
}; }, options);
const app = getApp(config); const app = getApp(config);
const server = app.listen(app.get('port'), () => { const server = app.listen(app.get('port'), () => {

51
lib/server-impl.test.js Normal file
View File

@ -0,0 +1,51 @@
'use strict';
const test = require('ava');
const proxyquire = require('proxyquire');
const getApp = proxyquire('./app', {
'./routes': {
createAPI: () => {},
createLegacy: () => {},
},
});
const serverImpl = proxyquire('./server-impl', {
'./app': getApp,
'./metrics': {
startMonitoring (o) {
return o;
},
},
'./db': {
createStores (o) {
return o;
},
},
'./options': {
createOptions (o) {
return o;
},
},
'../migrator' () {
return Promise.resolve();
},
});
test('should call preHook', async t => {
let called = 0;
await serverImpl.start({
preHook: () => {
called++;
},
});
t.true(called === 1);
});
test('should call preRouterHook', async t => {
let called = 0;
await serverImpl.start({ preRouterHook: () => {
called++;
} });
t.true(called === 1);
});