Fixed the log class and updated tests
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Sambo Chea 2021-03-10 21:55:41 +07:00
parent 010dda1cad
commit 478c7ab38f
3 changed files with 15 additions and 15 deletions

View File

@ -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;

View File

@ -1,7 +1,7 @@
type LogType = 'info' | 'error' | 'warn'
export type LogType = 'info' | 'error' | 'warn';
export interface Loggable {
type: LogType;
from?: string;
data?: any;
}
}

View File

@ -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'