Browse Source

mute logging in tests

Richard Köhl 2 years ago
parent
commit
6891f36477

+ 16 - 8
src/infrastructure/logger.ts

@@ -56,32 +56,40 @@ export class Logger {
     return this.loggerName === 'test';
     return this.loggerName === 'test';
   }
   }
 
 
-  public debug(message: string) {
-    this.logger.debug(message);
+  public debug(message: string): void {
     if (this.isTest()) {
     if (this.isTest()) {
       this.messages.push('[DEBUG] ' + message);
       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()) {
     if (this.isTest()) {
       this.messages.push('[INFO] ' + message);
       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()) {
     if (this.isTest()) {
       this.messages.push('[WARNING] ' + message);
       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()) {
     if (this.isTest()) {
       this.messages.push('[ERROR] ' + message);
       this.messages.push('[ERROR] ' + message);
+      return;
     }
     }
+
+    this.logger.error(message);
   }
   }
 
 
   public getMessages(): string[] {
   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);
   controller.setHandler('/', 'GET', errorHandler);
 
 
   // Test that the handler was stored correctly
   // Test that the handler was stored correctly