aboutsummaryrefslogtreecommitdiffstats
path: root/packages/main/src/utils
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2021-12-31 01:52:28 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2021-12-31 01:56:30 +0100
commit7108c642f4ff6dc5f0c4d30b8a8960064ff8e90f (patch)
treef8c0450a6e1b62f7e7f8470efd375b3659b91b2b /packages/main/src/utils
parentrefactor: Install devtools extensions earlier (diff)
downloadsophie-7108c642f4ff6dc5f0c4d30b8a8960064ff8e90f.tar.gz
sophie-7108c642f4ff6dc5f0c4d30b8a8960064ff8e90f.tar.zst
sophie-7108c642f4ff6dc5f0c4d30b8a8960064ff8e90f.zip
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.
Diffstat (limited to 'packages/main/src/utils')
-rw-r--r--packages/main/src/utils/index.ts2
-rw-r--r--packages/main/src/utils/logging.ts16
2 files changed, 13 insertions, 5 deletions
diff --git a/packages/main/src/utils/index.ts b/packages/main/src/utils/index.ts
index 9a57e02..2b85989 100644
--- a/packages/main/src/utils/index.ts
+++ b/packages/main/src/utils/index.ts
@@ -22,4 +22,4 @@ import { IDisposer } from 'mobx-state-tree';
22 22
23export type Disposer = IDisposer; 23export type Disposer = IDisposer;
24 24
25export { getLogger } from './logging'; 25export { getLogger, silenceLogger } from './logging';
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 @@
18 * SPDX-License-Identifier: AGPL-3.0-only 18 * SPDX-License-Identifier: AGPL-3.0-only
19 */ 19 */
20 20
21import chalk, { ChalkInstance } from 'chalk'; 21import chalk, { Chalk } from 'chalk';
22import loglevel, { Logger } from 'loglevel'; 22import loglevel, { Logger } from 'loglevel';
23import prefix from 'loglevel-plugin-prefix'; 23import prefix from 'loglevel-plugin-prefix';
24 24
25if (import.meta.env.DEV) { 25if (import.meta.env?.DEV) {
26 loglevel.setLevel('debug'); 26 loglevel.setLevel('debug');
27} else { 27} else {
28 loglevel.setLevel('info'); 28 loglevel.setLevel('info');
29} 29}
30 30
31const COLORS: Partial<Record<string, ChalkInstance>> = { 31const COLORS: Partial<Record<string, Chalk>> = {
32 TRACE: chalk.magenta, 32 TRACE: chalk.magenta,
33 DEBUG: chalk.cyan, 33 DEBUG: chalk.cyan,
34 INFO: chalk.blue, 34 INFO: chalk.blue,
@@ -37,7 +37,7 @@ const COLORS: Partial<Record<string, ChalkInstance>> = {
37 CRITICAL: chalk.red, 37 CRITICAL: chalk.red,
38}; 38};
39 39
40function getColor(level: string): ChalkInstance { 40function getColor(level: string): Chalk {
41 return COLORS[level] ?? chalk.gray; 41 return COLORS[level] ?? chalk.gray;
42} 42}
43 43
@@ -52,3 +52,11 @@ prefix.apply(loglevel, {
52export function getLogger(loggerName: string): Logger { 52export function getLogger(loggerName: string): Logger {
53 return loglevel.getLogger(loggerName); 53 return loglevel.getLogger(loggerName);
54} 54}
55
56export function silenceLogger(): void {
57 loglevel.disableAll();
58 const loggers = loglevel.getLoggers();
59 for (const loggerName of Object.keys(loggers)) {
60 loggers[loggerName].disableAll();
61 }
62}