From 2c594910d85efb22e7dbea5b8b2ba232da036477 Mon Sep 17 00:00:00 2001 From: Zameer Haque <20766601+haquezameer@users.noreply.github.com> Date: Sun, 19 Sep 2021 23:50:46 +0530 Subject: [PATCH] fix: do not throw multiple logger deprecation warning if using default logger config (#2446) --- .changeset/shaggy-carrots-unite.md | 5 +++++ packages/logger/src/logger.ts | 2 +- packages/logger/test/logger.spec.ts | 25 +++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 .changeset/shaggy-carrots-unite.md diff --git a/.changeset/shaggy-carrots-unite.md b/.changeset/shaggy-carrots-unite.md new file mode 100644 index 000000000..83acb1e16 --- /dev/null +++ b/.changeset/shaggy-carrots-unite.md @@ -0,0 +1,5 @@ +--- +'@verdaccio/logger': patch +--- + +do not show deprecation warning on default logger config diff --git a/packages/logger/src/logger.ts b/packages/logger/src/logger.ts index cb0d1ef4d..4ba82a207 100644 --- a/packages/logger/src/logger.ts +++ b/packages/logger/src/logger.ts @@ -98,7 +98,7 @@ export type LoggerConfigItem = { export type LoggerConfig = LoggerConfigItem[]; -export function setup(options: LoggerConfig | LoggerConfigItem = [DEFAULT_LOGGER_CONF]) { +export function setup(options: LoggerConfig | LoggerConfigItem = DEFAULT_LOGGER_CONF) { debug('setup logger'); const isLegacyConf = Array.isArray(options); if (isLegacyConf) { diff --git a/packages/logger/test/logger.spec.ts b/packages/logger/test/logger.spec.ts index ab9a05877..43b789201 100644 --- a/packages/logger/test/logger.spec.ts +++ b/packages/logger/test/logger.spec.ts @@ -13,4 +13,29 @@ describe('logger', () => { // FIXME: check expect // expect(spyOn).toHaveBeenCalledTimes(2); }); + + test('throw deprecation warning if multiple loggers configured', () => { + const spy = jest.spyOn(process, 'emitWarning'); + setup([ + { + level: 'info', + }, + { + level: 'http', + }, + ]); + expect(spy).toHaveBeenCalledWith( + 'deprecate: multiple logger configuration is deprecated, please check the migration guide.' + ); + spy.mockRestore(); + }); + + test('regression: do not throw deprecation warning if no logger config is provided', () => { + const spy = jest.spyOn(process, 'emitWarning'); + setup(); + expect(spy).not.toHaveBeenCalledWith( + 'deprecate: multiple logger configuration is deprecated, please check the migration guide.' + ); + spy.mockRestore(); + }); });