浏览代码

mute logging in tests

Richard Köhl 2 年之前
父节点
当前提交
6891f36477
共有 2 个文件被更改,包括 17 次插入9 次删除
  1. 16 8
      src/infrastructure/logger.ts
  2. 1 1
      test/interfaces/controllers/controller.class.test.ts

+ 16 - 8
src/infrastructure/logger.ts

@@ -56,32 +56,40 @@ export class Logger {
     return this.loggerName === 'test';
   }
 
-  public debug(message: string) {
-    this.logger.debug(message);
+  public debug(message: string): void {
     if (this.isTest()) {
       this.messages.push('[DEBUG] ' + message);
+      return;
     }
+
+    this.logger.debug(message);
   }
 
-  public info(message: string) {
-    this.logger.info(message);
+  public info(message: string): void {
     if (this.isTest()) {
       this.messages.push('[INFO] ' + message);
+      return;
     }
+
+    this.logger.info(message);
   }
 
-  public warn(message: string) {
-    this.logger.warning(message);
+  public warn(message: string): void {
     if (this.isTest()) {
       this.messages.push('[WARNING] ' + message);
+      return;
     }
+
+    this.logger.warning(message);
   }
 
-  public error(message: string) {
-    this.logger.error(message);
+  public error(message: string): void {
     if (this.isTest()) {
       this.messages.push('[ERROR] ' + message);
+      return;
     }
+
+    this.logger.error(message);
   }
 
   public getMessages(): string[] {

+ 1 - 1
test/interfaces/controllers/controller.class.test.ts

@@ -68,7 +68,7 @@ Deno.test('Controller class error handling', async () => {
     });
   };
 
-  const controller = new Controller();
+  const controller = new Controller({}, testLogger);
   controller.setHandler('/', 'GET', errorHandler);
 
   // Test that the handler was stored correctly