From f4667fa76764a54c1bd9d5892d01a300135350fd Mon Sep 17 00:00:00 2001 From: ivaosthu Date: Tue, 18 Jun 2019 19:59:24 +0200 Subject: [PATCH] chore: add a test to verify eventHook registration --- lib/server-impl.test.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/server-impl.test.js b/lib/server-impl.test.js index 711dde924e..adde6d2367 100644 --- a/lib/server-impl.test.js +++ b/lib/server-impl.test.js @@ -2,6 +2,7 @@ const test = require('ava'); const proxyquire = require('proxyquire'); +const { EventEmitter } = require('events'); const express = require('express'); const getLogger = require('../test/fixtures/no-logger'); @@ -13,6 +14,8 @@ const getApp = proxyquire('./app', { }, }); +const eventStore = new EventEmitter(); + const serverImpl = proxyquire('./server-impl', { './app': getApp, './metrics': { @@ -21,8 +24,10 @@ const serverImpl = proxyquire('./server-impl', { }, }, './db': { - createStores(o) { - return o; + createStores() { + return { + eventStore, + }; }, }, './options': { @@ -58,3 +63,16 @@ test('should call preRouterHook', async t => { }); t.true(called === 1); }); + +test('should call eventHook', async t => { + let called = 0; + await serverImpl.start({ + port: 0, + getLogger, + eventHook: () => { + called++; + }, + }); + eventStore.emit('feature-created', {}); + t.true(called === 1); +});