Simplify logger creation in tests

This commit is contained in:
Fredrik Adelöw
2020-05-06 13:30:58 +02:00
parent 425cf93c08
commit 5961be5861
2 changed files with 4 additions and 14 deletions
@@ -14,18 +14,13 @@
* limitations under the License.
*/
import { PassThrough } from 'stream';
import winston from 'winston';
import { getRootLogger, setRootLogger } from './rootLogger';
describe('rootLogger', () => {
it('can replace the default logger', () => {
const logger = winston.createLogger({
transports: [
new winston.transports.Stream({ stream: new PassThrough() }),
],
});
jest.spyOn(logger, 'info');
const logger = winston.createLogger();
jest.spyOn(logger, 'info').mockReturnValue(logger);
setRootLogger(logger);
getRootLogger().info('testing');
@@ -15,19 +15,14 @@
*/
import express from 'express';
import { PassThrough } from 'stream';
import request from 'supertest';
import winston from 'winston';
import { requestLoggingHandler } from './requestLoggingHandler';
describe('requestLoggingHandler', () => {
it('emits logs for each request', async () => {
const logger = winston.createLogger({
transports: [
new winston.transports.Stream({ stream: new PassThrough() }),
],
});
jest.spyOn(logger, 'info');
const logger = winston.createLogger();
jest.spyOn(logger, 'info').mockReturnValue(logger);
const app = express();
app.use(requestLoggingHandler(logger));