From 7108c642f4ff6dc5f0c4d30b8a8960064ff8e90f Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Fri, 31 Dec 2021 01:52:28 +0100 Subject: test: Add tests for main package - Changed jest to run from the root package and reference the packages as projects. This required moving the base jest config file away from the project root. - Module isolation seems to prevent ts-jest from loading the shared package, so we disabled it for now. - To better facilitate mocking, services should be split into interfaces and implementation - Had to downgrade to chald 4.1.2 as per https://github.com/chalk/chalk/releases/tag/v5.0.0 at least until https://github.com/microsoft/TypeScript/issues/46452 is resolved. --- packages/main/src/utils/logging.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'packages/main/src/utils/logging.ts') diff --git a/packages/main/src/utils/logging.ts b/packages/main/src/utils/logging.ts index 6c4cba2..ed40365 100644 --- a/packages/main/src/utils/logging.ts +++ b/packages/main/src/utils/logging.ts @@ -18,17 +18,17 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -import chalk, { ChalkInstance } from 'chalk'; +import chalk, { Chalk } from 'chalk'; import loglevel, { Logger } from 'loglevel'; import prefix from 'loglevel-plugin-prefix'; -if (import.meta.env.DEV) { +if (import.meta.env?.DEV) { loglevel.setLevel('debug'); } else { loglevel.setLevel('info'); } -const COLORS: Partial> = { +const COLORS: Partial> = { TRACE: chalk.magenta, DEBUG: chalk.cyan, INFO: chalk.blue, @@ -37,7 +37,7 @@ const COLORS: Partial> = { CRITICAL: chalk.red, }; -function getColor(level: string): ChalkInstance { +function getColor(level: string): Chalk { return COLORS[level] ?? chalk.gray; } @@ -52,3 +52,11 @@ prefix.apply(loglevel, { export function getLogger(loggerName: string): Logger { return loglevel.getLogger(loggerName); } + +export function silenceLogger(): void { + loglevel.disableAll(); + const loggers = loglevel.getLoggers(); + for (const loggerName of Object.keys(loggers)) { + loggers[loggerName].disableAll(); + } +} -- cgit v1.2.3-54-g00ecf