2017-08-04 16:03:15 +02:00
|
|
|
'use strict';
|
|
|
|
|
2018-12-17 09:24:49 +01:00
|
|
|
const test = require('ava');
|
2017-08-04 16:03:15 +02:00
|
|
|
const createLogger = require('./logger');
|
|
|
|
const logger = require('../logger');
|
|
|
|
|
|
|
|
test('should expose a setLoggerProvider function', t => {
|
|
|
|
t.true(logger.setLoggerProvider instanceof Function);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should create logger via custom logger provider', t => {
|
|
|
|
const loggerName = 'test';
|
2017-08-05 15:38:55 +02:00
|
|
|
const loggerImpl = {
|
|
|
|
debug: () => {},
|
|
|
|
info: () => {},
|
|
|
|
warn: () => {},
|
|
|
|
error: () => {},
|
|
|
|
};
|
|
|
|
const provider = () => loggerImpl;
|
2017-08-04 16:03:15 +02:00
|
|
|
logger.setLoggerProvider(provider);
|
|
|
|
|
|
|
|
const log = createLogger(loggerName);
|
|
|
|
|
|
|
|
t.is(log, loggerImpl);
|
|
|
|
});
|
2017-08-05 15:38:55 +02:00
|
|
|
|
|
|
|
test('should require custom logger to implement info', t => {
|
|
|
|
const loggerImpl = {
|
|
|
|
debug: () => {},
|
|
|
|
warn: () => {},
|
|
|
|
error: () => {},
|
|
|
|
};
|
|
|
|
const provider = () => loggerImpl;
|
|
|
|
const error = t.throws(() => {
|
|
|
|
logger.setLoggerProvider(provider)();
|
|
|
|
}, TypeError);
|
|
|
|
t.is(error.message, 'Logger must implement info');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should require custom logger to implement error', t => {
|
|
|
|
const loggerImpl = {
|
|
|
|
debug: () => {},
|
|
|
|
warn: () => {},
|
|
|
|
info: () => {},
|
|
|
|
};
|
|
|
|
const provider = () => loggerImpl;
|
|
|
|
const error = t.throws(() => {
|
|
|
|
logger.setLoggerProvider(provider)();
|
|
|
|
}, TypeError);
|
|
|
|
t.is(error.message, 'Logger must implement error');
|
|
|
|
});
|