1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00
unleash.unleash/lib/server-impl.test.js
ivaosthu ccaab0c47b fix: LogProvider as option injected to unleash.
Instead of instructing users to do static calls
in to Unleash, she should instead be allwed to
specify the log provider as an option to Unleash.

This commit introduces the "getLogger" option,
a function responsible for creating a logger.
2020-02-20 08:34:24 +01:00

61 lines
1.1 KiB
JavaScript

'use strict';
const test = require('ava');
const proxyquire = require('proxyquire');
const express = require('express');
const getLogger = require('../test/fixtures/no-logger');
const getApp = proxyquire('./app', {
'./routes': class Index {
router() {
return express.Router();
}
},
});
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({
port: 0,
getLogger,
preHook: () => {
called++;
},
});
t.true(called === 1);
});
test('should call preRouterHook', async t => {
let called = 0;
await serverImpl.start({
port: 0,
getLogger,
preRouterHook: () => {
called++;
},
});
t.true(called === 1);
});