From 478c7ab38fb0f446243f6bb6369b45064f15037f Mon Sep 17 00:00:00 2001 From: Sambo Chea Date: Wed, 10 Mar 2021 21:55:41 +0700 Subject: [PATCH] Fixed the log class and updated tests --- src/log/{Log.ts => index.ts} | 16 ++++++++-------- src/log/interfaces.ts | 4 ++-- tests/log.test.ts | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) rename src/log/{Log.ts => index.ts} (57%) diff --git a/src/log/Log.ts b/src/log/index.ts similarity index 57% rename from src/log/Log.ts rename to src/log/index.ts index 9ecba17..bf32174 100644 --- a/src/log/Log.ts +++ b/src/log/index.ts @@ -1,16 +1,16 @@ -import { Loggable } from "./interfaces"; +import { Loggable } from './interfaces'; -class Log { +class Index { static log(loggable: Loggable): void { switch (loggable.type) { case 'error': - this.error(loggable.from, loggable.data) + this.error(loggable.from, loggable.data); break; case 'warn': - this.warn(loggable.from, loggable.data) + this.warn(loggable.from, loggable.data); break; default: - this.info(loggable.from, loggable.data) + this.info(loggable.from, loggable.data); break; } } @@ -20,12 +20,12 @@ class Log { } static error(...data: any[]): void { - console.error(data) + console.error(data); } static warn(...data: any[]): void { - console.warn(data) + console.warn(data); } } -export default Log; +export default Index; diff --git a/src/log/interfaces.ts b/src/log/interfaces.ts index 05d3331..609cbbe 100644 --- a/src/log/interfaces.ts +++ b/src/log/interfaces.ts @@ -1,7 +1,7 @@ -type LogType = 'info' | 'error' | 'warn' +export type LogType = 'info' | 'error' | 'warn'; export interface Loggable { type: LogType; from?: string; data?: any; -} \ No newline at end of file +} diff --git a/tests/log.test.ts b/tests/log.test.ts index d8c3717..a19c288 100644 --- a/tests/log.test.ts +++ b/tests/log.test.ts @@ -1,20 +1,20 @@ -import Log from '../src/log/Log'; +import Index from '../src/Log'; describe('logging into console', function () { it('info', function () { - Log.info('I am an info!'); + Index.info('I am an info!'); }); it('warn', function () { - Log.info('I am a warn!'); + Index.info('I am a warn!'); }); it('error', function () { - Log.info('I am an error!'); + Index.info('I am an error!'); }); it('loggable', function () { - Log.log({ + Index.log({ type: 'info', from: 'log.test.ts', data: 'I am loggable called'