From efe66c3ff9b781d5ef2437462b08aabead0c1eca Mon Sep 17 00:00:00 2001 From: sveisvei Date: Tue, 6 Jun 2017 09:56:29 +0200 Subject: [PATCH 1/2] pass along hooks, add test to server impl --- .eslintrc | 3 +++ lib/server-impl.js | 2 ++ lib/server-impl.test.js | 51 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 lib/server-impl.test.js diff --git a/.eslintrc b/.eslintrc index 047272e06d..2c8ac6c0ac 100644 --- a/.eslintrc +++ b/.eslintrc @@ -3,6 +3,9 @@ "finn", "finn/node" ], + "parserOptions": { + "ecmaVersion": "2017" + }, "rules": { "max-nested-callbacks": "off" } diff --git a/lib/server-impl.js b/lib/server-impl.js index 500c5b8f1e..df4dd0a2cb 100644 --- a/lib/server-impl.js +++ b/lib/server-impl.js @@ -21,6 +21,8 @@ function createApp (options) { enableRequestLogger: options.enableRequestLogger, port: options.port, publicFolder: options.publicFolder, + preRouterHook: options.preRouterHook, + preHook: options.preHook, stores, eventBus, }; diff --git a/lib/server-impl.test.js b/lib/server-impl.test.js new file mode 100644 index 0000000000..0a295f2900 --- /dev/null +++ b/lib/server-impl.test.js @@ -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); +}); From 94fdbdb58b6438cdcf21874e3e8beb9d2912e4d8 Mon Sep 17 00:00:00 2001 From: sveisvei Date: Tue, 6 Jun 2017 10:17:15 +0200 Subject: [PATCH 2/2] use object.assign and pass along options --- lib/server-impl.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/server-impl.js b/lib/server-impl.js index df4dd0a2cb..b251461fbc 100644 --- a/lib/server-impl.js +++ b/lib/server-impl.js @@ -15,17 +15,10 @@ function createApp (options) { const stores = createStores(options); const eventBus = new EventEmitter(); - const config = { - baseUriPath: options.baseUriPath, - serverMetrics: options.serverMetrics, - enableRequestLogger: options.enableRequestLogger, - port: options.port, - publicFolder: options.publicFolder, - preRouterHook: options.preRouterHook, - preHook: options.preHook, + const config = Object.assign({ stores, eventBus, - }; + }, options); const app = getApp(config); const server = app.listen(app.get('port'), () => {