From 3c2c4ee838ac1b0b8e9dcd42088eba8c261c5932 Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Thu, 28 Mar 2019 11:52:29 +0100 Subject: [PATCH] refactor: upgrades "winston" package to v3 --- lib/logger.js | 18 +++++++------ lib/reporters/reporterOutputLogger.js | 34 +++++++++++++------------ package.json | 2 +- test/unit/reporters/CLIReporter-test.js | 12 ++++++--- 4 files changed, 37 insertions(+), 29 deletions(-) diff --git a/lib/logger.js b/lib/logger.js index 97e27005d..9a88e568d 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -1,17 +1,19 @@ -const winston = require('winston'); +const { createLogger, transports, format } = require('winston'); -module.exports = new (winston.Logger)({ +module.exports = new createLogger({ transports: [ - new (winston.transports.Console)({ colorize: true }), + new transports.Console({ colorize: true }), ], levels: { debug: 2, warn: 1, error: 0, }, - colors: { - debug: 'cyan', - warn: 'yellow', - error: 'red', - }, + format: format.colorize({ + colors: { + debug: 'cyan', + warn: 'yellow', + error: 'red', + }, + }), }); diff --git a/lib/reporters/reporterOutputLogger.js b/lib/reporters/reporterOutputLogger.js index 93b8cf03c..17b74d3cf 100644 --- a/lib/reporters/reporterOutputLogger.js +++ b/lib/reporters/reporterOutputLogger.js @@ -1,8 +1,8 @@ -const winston = require('winston'); +const { createLogger, transports, format } = require('winston'); -module.exports = new (winston.Logger)({ +module.exports = new createLogger({ transports: [ - new (winston.transports.Console)({ colorize: true, level: 'info' }), + new transports.Console({ colorize: true, level: 'info' }), ], levels: { info: 10, @@ -17,17 +17,19 @@ module.exports = new (winston.Logger)({ skip: 1, error: 0, }, - colors: { - info: 'blue', - test: 'yellow', - pass: 'green', - fail: 'red', - complete: 'green', - actual: 'red', - expected: 'red', - hook: 'green', - request: 'green', - skip: 'yellow', - error: 'red', - }, + format: format.colorize({ + colors: { + info: 'blue', + test: 'yellow', + pass: 'green', + fail: 'red', + complete: 'green', + actual: 'red', + expected: 'red', + hook: 'green', + request: 'green', + skip: 'yellow', + error: 'red', + }, + }), }); diff --git a/package.json b/package.json index 6e5e6679c..9ff563002 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "untildify": "3.0.3", "uuid": "3.3.2", "which": "1.3.1", - "winston": "2.4.0" + "winston": "3.2.1" }, "devDependencies": { "@commitlint/cli": "7.5.2", diff --git a/test/unit/reporters/CLIReporter-test.js b/test/unit/reporters/CLIReporter-test.js index 8c253c747..ec8a5bcdb 100644 --- a/test/unit/reporters/CLIReporter-test.js +++ b/test/unit/reporters/CLIReporter-test.js @@ -15,13 +15,17 @@ describe('CLIReporter', () => { let test = {}; before(() => { - loggerStub.transports.console.silent = true; - reporterOutputLoggerStub.transports.console.silent = true; + [loggerStub, reporterOutputLoggerStub].forEach((logger) => { + logger.configure({ silent: true }); + }) }); after(() => { - loggerStub.transports.console.silent = false; - reporterOutputLoggerStub.transports.console.silent = false; + // Is this really a good idea to mutate logger instances + // vs creating logger instances for tests using the same factory function? + [loggerStub, reporterOutputLoggerStub].forEach((logger) => { + logger.configure({ silent: false }); + }) }); describe('when starting', () => {